这个问题相当简单,但我无法理解它。
待处理以下api
{ "data" : [ { "id" : "102",
"sector" : "projectSector1",
"title" : "projectTitle1"
},
{ "id" : "100",
"sector" : "projectSector2",
"title" : "projectTitle2"
},
{ "id" : "98",
"sector" : "projectSector3",
"title" : "projectTitle3"
}
],
"status" : "success"
}
所以在我的doInBackground
我运行以下代码:
protected Void doInBackground(Void... params) {
UserFunctions user = new UserFunctions();
JSob = user.allprojects();
try {
JSar = JSob.getJSONArray("data");
} catch (JSONException e1) {
e1.printStackTrace();
}
for(int i=0; i<JSar.length(); i++){
try {
JSONObject newobj = JSar.getJSONObject(i);
project_title = newobj.getString("title");
project_sector = newobj.getString("sector");
all_list.put("title", project_title);
all_list.put("sector", project_sector);
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
在这里,我试图HashMap
(all_list
即 hashMap)将“扇区”和“标题”作为键,并将它们的相应值作为值。但由于某种原因,我只能访问 projectTitle3 和 projectSector3 两次。请帮忙 !