json-lib-2.3-jdk13.jar,ezmorph-1.0.3.jar,commons-lang.jar,commons-logging.jar,commons-beanutils.jar,xom-1.1.jar,commons-collections-3.2.jar
可以下载jar包的网站http://www.docjar.com/
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
String myjson =
"{name=\"json\",bool:true,int:1,double:2.2,function:function(a){return a;},array:[1,2]}";
JSONObject json1 = JSONObject.fromObject(myjson);
System.out.println(json1.get("name"));//输出为json
String str = "{\"p\":[{name:1,add:2},{name:2,add:3}],\"q\":{tel:12,id:23}}";
JSONArray arr = json1.getJSONArray("p");
for (int i=0;i<arr.size();i++){
System.out.println(arr.getJSONObject(i).get("name")+" "+arr.getJSONObject(i).get("add"));
}
System.out.println(json1.getJSONObject("q").get("tel")+" "+json1.getJSONObject("q").get("id"));
}
}
可以下载jar包的网站http://www.docjar.com/
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
String myjson =
"{name=\"json\",bool:true,int:1,double:2.2,function:function(a){return a;},array:[1,2]}";
JSONObject json1 = JSONObject.fromObject(myjson);
System.out.println(json1.get("name"));//输出为json
String str = "{\"p\":[{name:1,add:2},{name:2,add:3}],\"q\":{tel:12,id:23}}";
JSONArray arr = json1.getJSONArray("p");
for (int i=0;i<arr.size();i++){
System.out.println(arr.getJSONObject(i).get("name")+" "+arr.getJSONObject(i).get("add"));
}
System.out.println(json1.getJSONObject("q").get("tel")+" "+json1.getJSONObject("q").get("id"));
}
}