Android中解析jsonObject和jsonArray

/**
* 这样相当于一个person数组

*/
// { "people": [
// { "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
// { "firstName": "Jason", "lastName":"Hunter", "email": "bbbb"},
// { "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
// ]}

                       /**
* 解析json数组
* 注意这里arg0.result的内容即为上面的people数组的内容
* 这里就省略了读取的方法

*/


try {
JSONObject jo = new JSONObject(arg0.result);
JSONArray array = jo.getJSONArray("people");
for(int i=0;i<array.length();i++){
String str = array.getString(i);
JSONObject object = new JSONObject(str);
String firstName = object.getString("firstName");
String lastName = object.getString("lastName");
String email = object.getString("email");


Log.i("main", "--------------");
Log.i("main", "firstName="+firstName);
Log.i("main", "lastName="+lastName);
Log.i("main", "email="+email);


}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}



你可能感兴趣的:(Android中解析jsonObject和jsonArray)