【发布时间】:2019-09-05 07:28:26
【问题描述】:
当 JSON 为空时显示此错误:org.json.JSONException: answerList 没有价值
{
"answerList": [
{
"id": 117,
"edu_forum_id": 167,
"edu_forum_answer_id": 0,
"answer": "cvf",
"attachment": "https://testapi.ourschoolzone.org/uploads/upload_eafd8dec-8237-43f0-ae83-7ad05df6209f_cropped6342785145197935935.jpg",
"answerdate": "31/08/2019 04:32 PM",
"school_id": "142388",
"school_name": "Demo-Irvine High School",
"school_address": "Panbazar, Guwahati, Assam",
"school_logo": "http://test.ourschoolzone.org/Upload/9873c7ee-1542-4b42-ba17-771d0b99f26f.png",
"parent_id": "3916",
"parent_name": "Intiaz Khan",
"parent_profile_image": "https://admin.ourschoolzone.org/Images/male_icon.png",
"teacher_id": "",
"teacher_name": "",
"teacher_profile_image": "https://test.ourschoolzone.org/Upload/a0ae18da-940b-47ee-86b1-b159318a0cd6.jpg"
},
这是使用 Volley 的 StringRequest。我正在获取 ListView 中的所有详细信息
try {
//getting the whole json object from the response
JSONObject obj = new JSONObject(response);
Log.e("ResponSe",response);
//we have the array named hero inside the object
//so here we are getting that json array
JSONArray heroArray = obj.getJSONArray("answerList");
//now looping through all the elements of the json array
for (int i = 0; i < heroArray.length(); i++) {
//getting the json object of the particular index inside the array
JSONObject heroObject = heroArray.getJSONObject(i);
//creating a hero object and giving them the values from json object
ViewAnswersModel hero = new ViewAnswersModel(heroObject.getString("answer"),
heroObject.getString("answerdate"),
heroObject.getString("school_name"),
heroObject.getString("school_logo"),
heroObject.getString("attachment"));
//adding the hero to herolist
heroList.add(hero);
}
**
如何显示未找到条目的 toast !
**
【问题讨论】:
-
if(answerlist.size()==0) Toast.show();
-
这对我不起作用!
标签: android json android-toast