android json数据解析

http://www.open-open.com/lib/view/open1326376799874.html

http://104zz.iteye.com/blog/1686120

多个json数据{"singers":[{'id':02,'name':'tom','gender':'男'},{'id':03,'name':'jerry,'gender':'男'},{'id':04,'name':'jim,'gender':'男'}]}

private void parseJsonMulti(String strResult) {
try {

//取出 以singers为key的值(数组)   [{'id':02,'name':'tom','gender':'男'},{'id':03,'name':'jerry,'gender':'男'},{'id':04,'name':'jim,'gender':'男'}]

取出的是个数组,所以要用 JSONArray 
JSONArray jsonObjs = new JSONObject(strResult).getJSONArray("singers"); 
String s = "";
for(int i = 0; i < jsonObjs.length() ; i++){
JSONObject jsonObj = ((JSONObject)jsonObjs.opt(i)).getJSONObject("singer");
int id = jsonObj.getInt("id");
String name = jsonObj.getString("name");
String gender = jsonObj.getString("gender");
s += "ID号"+id + ", 姓名:" + name + ",性别:" + gender+ " " ;
}
tvJson.setText(s);
} catch (JSONException e) {
System.out.println("Jsons parse error !");
e.printStackTrace();

}

}

try {      JSONTokener jsonParser = new JSONTokener(JSON);  

   // 此时还未读取任何json文本,直接读取就是一个JSONObject对象。  

    // 如果此时的读取位置在"name" : 了,那么nextValue就是"yuanzhifei89"(String)  

    JSONObject person = (JSONObject) jsonParser.nextValue();  

    // 接下来的就是JSON对象的操作了  

    person.getJSONArray("phone");  

    person.getString("name");  

    person.getInt("age");  

    person.getJSONObject("address");  

    person.getBoolean("married");  

catch (JSONException ex) {  

    // 异常处理代码  

}  

原文地址:https://www.cnblogs.com/stallran/p/3694885.html