// 第一個要解析的json resultJson = {
"name":"python",
"num":9999,
"students":{
"stu1":"aaa",
"stu2":"bbb",
"stu3":"ccc"
}
}
// 獲取String類型name String name = resultJson.getString("name"); // 獲取int類型num int num = resultJson.getInt("num"); // 獲取students對應的value值,得到一個JSONObject對象 JSONObject students = resultJson.getJSONObject("students"); // 獲取students子對象中stu1對應的值 String stu1 = resultJson.getJSONObject("students").getString("stu1");
// 第二個要解析的json resultJson = { "name":"python", "num":9999, "students":[ { "stu1":"aaa", "age":28 }, { "stu2":"bbb", "age":20 } ] }
// 獲取students對應的value值,得到一個JSONOArray對象 JSONArray students = resultJson.getJSONArray("students"); // 獲取students數組,第一個子對象的值 JSONObject student1 = resultJson.getJSONArray("students").getJSONObject(0);