为什么Json测试程序不起作用?
当我使用jdk 7运行Json测试程序时,它说:
Exception in thread "main" javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
at javax.json.spi.JsonProvider.provider(JsonProvider.java:97)
at javax.json.Json.createArrayBuilder(Json.java:257)"
我已经在我的项目中包含了“javax.json-api-1.0.jar”。
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class JsonExample
{
public static void main(String[] args)
{
List<User> users=getUsers();
// build JSON
JsonArrayBuilder jsonArrayBuilder=Json.createArrayBuilder();
for (User user : users)
{
jsonArrayBuilder.add(
Json.createObjectBuilder()
.add("id",user.getId())
.add("name",user.getName())
.add("join",user.getJoin().getTime()));
}
JsonArray usersJson=jsonArrayBuilder.build();
System.out.println(usersJson.toString());
}
// dummy users
public static List<User> getUsers()
{
List<User> users=new ArrayList<User>(10);
User user=new User();
user.setId(1);
user.setName("Hero");
user.setJoin(new Date());
users.add(user);
user=new User();
user.setId(2);
user.setName("Citizen");
user.setJoin(new Date());
users.add(user);
return users;
}
// POJO
public static class User implements Serializable
{
private long id;
private String name;
private Date join;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id=id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public Date getJoin()
{
return join;
}
public void setJoin(Date join)
{
this.join=join;
}
}
}
这是一个简单的程序,不使用galssfish,为什么这里提到玻璃鱼?