关于字符串转换成json的总结

来源:互联网 发布:qq群淘宝客如何赚钱 编辑:程序博客网 时间:2024/04/30 12:59
String aa="[{\"id\":\"0\",\"name\":\"退役后\"}]";
try{
JSONArray json=JSONArray.fromObject(aa);
for (int i = 0; i < json.size(); i++) {
JSONObject jb=json.getJSONObject(i);
try{
String DM_OBJECTNAME=jb.getString("DM_LEASTVALUE");
String EQU="["+jb.getString("EQU")+"]";
System.out.println(DM_OBJECTNAME);
JSONArray equ=JSONArray.fromObject(EQU);
for (int j = 0; j < equ.size(); j++) {
JSONObject equo=equ.getJSONObject(j);
try{
String EQU_NAME=equo.getString("EQU_NAME");
System.out.println(EQU_NAME);
}catch(NullPointerException e){
System.out.println("判断json中的数据不能为null"+e);
}
}
}catch(NullPointerException e){
System.out.println("判断json中的数据不能为null"+e);
}
}
}catch(JSONException e){
System.out.println("判断json不能为null"+e);
}
原创粉丝点击