public void jsonTest(){
//创建一JSON
JSONObject object=new JSONObject();
//添加值
object.put("name", "张三");
object.put("sex", "男");
System.out.println(object);
//根据键得到值
Object str = object.get("name");
System.out.println("name:"+str);
//将Item转换为Array
JSONArray jsonArray=JSONArray.fromObject("");
for (int i=0;i<jsonArray.size();i++) {
JSONObject jb = jsonArray.getJSONObject(i);
jb.get("");
}
//判读输出对象的类型
boolean isArray = object.isArray();
boolean isEmpty = object.isEmpty();
boolean isNullObject = object.isNullObject();
System.out.println("Array:"+isArray+";----Empty:"+isEmpty+";---NullObject:"+isNullObject);
//添加属性
object.element("address", "福建省厦门市");
System.out.println("添加的属性值为==>"+object.get("address"));
//把字符转换为 JSONObject
String temp=object.toString();
JSONObject ss = JSONObject.fromObject(temp);
System.out.println("转换为字符串后的JSON对象"+ss);
}
//创建一JSON
JSONObject object=new JSONObject();
//添加值
object.put("name", "张三");
object.put("sex", "男");
System.out.println(object);
//根据键得到值
Object str = object.get("name");
System.out.println("name:"+str);
//将Item转换为Array
JSONArray jsonArray=JSONArray.fromObject("");
for (int i=0;i<jsonArray.size();i++) {
JSONObject jb = jsonArray.getJSONObject(i);
jb.get("");
}
//判读输出对象的类型
boolean isArray = object.isArray();
boolean isEmpty = object.isEmpty();
boolean isNullObject = object.isNullObject();
System.out.println("Array:"+isArray+";----Empty:"+isEmpty+";---NullObject:"+isNullObject);
//添加属性
object.element("address", "福建省厦门市");
System.out.println("添加的属性值为==>"+object.get("address"));
//把字符转换为 JSONObject
String temp=object.toString();
JSONObject ss = JSONObject.fromObject(temp);
System.out.println("转换为字符串后的JSON对象"+ss);
}