import org.json.JSONObject;
try {
JSONObject json = new JSONObject();
int totalProperty = json.getInt("totalProperty");
JSONObject root = json.getJSONObject("root");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
要取什么值就用getXXX的方法来取
JSONObject dataJson=new JSONObject("你的Json数据“);
int totalProperty=dataJson.getString("totalProperty");
JSONObject root=dataJson.getJSONObject("root");
JSONObject info=root.getJSONObject(0);
这样info就是数组:{"areainfocode": "001", "areainfoid": "asdfasdfa","areainfoname": "市南" }
用JSONArray解析,要么用Gson解析,JSONObject解析只能解析一条json数据,多条要用前面两个,而且json格式不能出错,百度上有很多例子,给你个网站看看:
网页链接