=================================================================
Object
----------------------------
第一种:Object
{"abc":"guochaoalng"}
解析方法
JSONObject demojson = new JSONObject(参数) 获取总的json数据
String abc = demojson.getString("abc");
---------------------------------------------------------------
第二种 Object
{"one":"guo","two":"chaolang"}
解析方法:
JSONObject demojson = new JSONObject(参数) 获取总的json数据
String abc = demojson.getString("one");
String xyz = demo.json.getString("two");
=================================================================
Array
------------------------------
第一种 Array
{"num":[1,2,3]}
解析方法:
JSONObject demojson = new JSONObject(参数) 获取总的json数据
JSONArray abc = demojson.getJSONArray("num");
for(int i=0;i<abc.length();i++){
Int temp = abc.getInt(i);
}
或
{"num":["one","two","three"]}
解析方法:
JSONObject demojson = new JSONObject(参数) 获取总的json数据
JSONArray abc = demojson.getJSONArray("num");
for(int i=0;i<abc.length();i++){
String temp = abc.getString(i);
}
-----------------------------------------------------------------
第二种 Array
{"num":[[1],[2],[3]]} 数组中嵌数组
解析方法:
JSONObject demojson = new JSONObject(参数) 获取总的json数据
JSONArray abc = demojson.getJSONArray("num");
for(int i=0;i<abc.length();i++){
Int temp = abc.getJSONArray(i).getInt(0);
//abc.getJSONArray(i).getString(3);
}
注:这里是第二层数组中只有一个元素,如果有多个可能需要用到二重循环
================================================================================
Object和Array混合
------------------------------------
{"a":[{"aa":"11"},{"aa":"12"}]}
解析方法:
JSONObject demojson = new JSONObject(参数) 获取总的json数据
JSONArray abc = demojson.getJSONArray("a");
for(int i=0;i<abc.length();i++){
String temp = abc.getJSONArray(i).getString("aa");
}
================================================================================