Android Can';无法检索具有子数组多个键值的JSON对象
我对安卓非常陌生。请帮助我获取下面引用的JSON文件中的所有数据。我能够获取每个JSON对象的JSON,但无法获取标记对象及其内部数组和键值。Android Can';无法检索具有子数组多个键值的JSON对象,android,arrays,json,Android,Arrays,Json,我对安卓非常陌生。请帮助我获取下面引用的JSON文件中的所有数据。我能够获取每个JSON对象的JSON,但无法获取标记对象及其内部数组和键值。 多谢各位 { "error": false, "terms": [{ "TermId": "1", "TermTitle": "Term1" }, { "TermId": "2", "TermTitle": "Term2" }, { "Term
多谢各位
{
"error": false,
"terms": [{
"TermId": "1",
"TermTitle": "Term1"
}, {
"TermId": "2",
"TermTitle": "Term2"
}, {
"TermId": "3",
"TermTitle": "Term3"
}],
"exams": [{
"TypeId": "1",
"TypeTitle": "Unit Test"
}, {
"TypeId": "2",
"TypeTitle": "PERIODIC TEST 1"
}, {
"TypeId": "3",
"TypeTitle": "PERIODIC TEST 2"
}, {
"TypeId": "4",
"TypeTitle": "HALF YEARLY EXAM"
}, {
"TypeId": "5",
"TypeTitle": "ANNUAL EXAM"
}, {
"TypeId": "6",
"TypeTitle": "PERIODIC TEST 3"
}, {
"TypeId": "7",
"TypeTitle": "QUARTERLY"
}],
"status": 0,
"exam": {
"examname": "PT3"
},
"marks": {
"Language 1 English": {
"Theory": ["", "25", "8", "18", "Passed"]
},
"Language 2 Malayalam": {
"Theory": ["", "25", "8", "12", "Passed"]
},
"Language 3 Hindi": {
"Theory": ["", "25", "8", "6", "Failed"]
},
"Mathematics": {
"Theory": ["", "25", "8", "16", "Passed"]
},
"EVS": {
"Theory": ["", "25", "8", "17", "Passed"]
},
"Computer": {
"Theory": ["", "25", "8", "23", "Passed"]
},
"Arabic": {
"Theory": ["", "25", "8", "18", "Passed"]
}
}
}
请使用此命令获取所有内部JsonArray
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response); //Response is your Json Response
//Getting "error" tag
Boolean error = jsonObject.getBoolean("error");
//Getting "terms" JsonArray
for (int i = 0; i < jsonObject.getJSONArray("terms").length(); i++) {
JSONObject jsonObject1 = jsonObject.getJSONArray("terms").getJSONObject(i);
String termId = jsonObject1.getString("TermId"); //Get Term id According to index
String TermTitle = jsonObject1.getString("TermTitle"); //Get Term Title According to index
}
//Getting "exams" JsonArray
for (int i = 0; i < jsonObject.getJSONArray("exams").length(); i++) {
JSONObject jsonObject1 = jsonObject.getJSONArray("terms").getJSONObject(i);
String termId = jsonObject1.getString("TermId"); //Get Term id According to index
String TermTitle = jsonObject1.getString("TermTitle"); //Get Term Title According to index
}
//Getting "status" tag
int status = jsonObject.getInt("status");
//Getting "examname" tag
String examname = jsonObject.getJSONObject("exam").getString("examname");
//Getting "marks" Json Object
JSONObject marksJsonObject = jsonObject.getJSONObject("marks");
//Getting "exams" JsonArray
for (int i = 0; i < marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("Language 2 Malayalam").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Language 2 Malayalam").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("Language 3 Hindi").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Language 3 Hindi").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("Mathematics").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Mathematics").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("EVS").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("EVS").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("Computer").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Computer").getJSONArray("Theory").get(i); //Get each Value According to index
}
for (int i = 0; i < marksJsonObject.getJSONObject("Arabic").getJSONArray("Theory").length(); i++) {
//JSONObject jsonObject1 = marksJsonObject.getJSONObject("Language 1 English").getJSONArray("Theory").get(i);
String values = (String) marksJsonObject.getJSONObject("Arabic").getJSONArray("Theory").get(i); //Get each Value According to index
}
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject JSONObject=null;
试一试{
jsonObject=newJSONObject(response);//response是您的Json响应
//获取“错误”标记
Boolean error=jsonObject.getBoolean(“错误”);
//获取“术语”JsonArray
for(int i=0;i
共享您现有的代码进程可能与我的代码中的terms数组重复。但是您可以这样做,并根据您的要求获取所有数组和对象。无法检索mark对象和其他数组对象。Term对象和Examies对象已被获取。等待,我将执行此操作。