使用的是json-lib-2.2.3-jdk.jar.但是这个jar文件还依赖到其他的jar文件。下面列出那些jar文件是必须的:
1.commons-beanutils.jar
2.commons-collections.jar
3.commons-lang.jar
4.commons-logging.jar
5.ezmorphy-1.0.3.jar
6.json-lib-2.2.3-jdk.jar
使用方法大抵如下:
public String getJSONObj()
{
String result = "";
User lzy = new User();
lzy.setAge(25);
lzy.setEmail("lzy.11111111@tom.com");
lzy.setPhoneNum("13611111111");
lzy.setUserName("lzy");
JSONObject json = new JSONObject();
json = JSONObject.fromObject(lzy);
result = json.toString();
System.out.println(json.toString());
return result;
}
public static void main(String[] args)
{
JSONTest test = new JSONTest();
test.getJSONObj();
}
1.commons-beanutils.jar
2.commons-collections.jar
3.commons-lang.jar
4.commons-logging.jar
5.ezmorphy-1.0.3.jar
6.json-lib-2.2.3-jdk.jar
使用方法大抵如下:
public String getJSONObj()
{
String result = "";
User lzy = new User();
lzy.setAge(25);
lzy.setEmail("lzy.11111111@tom.com");
lzy.setPhoneNum("13611111111");
lzy.setUserName("lzy");
JSONObject json = new JSONObject();
json = JSONObject.fromObject(lzy);
result = json.toString();
System.out.println(json.toString());
return result;
}
public static void main(String[] args)
{
JSONTest test = new JSONTest();
test.getJSONObj();
}