0
我無法從MAP中從下面的代碼讀取Arraylist的值,請建議應該做什麼。如何從java中的Map中讀取Arraylist的值
@Override
protected void onPostExecute(Map<String,List<CommentModel>> results) {
super.onPostExecute(results);
results.get(0).get(commentModelList);
Toast.makeText(getApplicationContext(), "Helloji" + results, Toast.LENGTH_LONG).show();
}
和值添加到地圖我認爲把值的地圖以正確的方式。請建議做什麼,因爲我卡在這裏。
String line = "";
StringBuffer buffer = new StringBuffer();
while ((line=bufferedReader.readLine())!=null){
buffer.append(line);
String result = buffer.toString();
JSONArray jsondata = new JSONArray(result);
commentModelList = new ArrayList<>();
commentModelList_child = new ArrayList<>();
map =new HashMap();
for(int i=0;i<=jsondata.length();i++){
CommentModel cmnmodel = new CommentModel();
JSONObject jsonObject = jsondata.getJSONObject(i);
int id= jsonObject.getInt("id");
String content = jsonObject.getString("content");
cmnmodel.setContent(content);
cmnmodel.setId(id);
commentModelList.add(cmnmodel);
commentModelList_child.add(cmnmodel);
map.put("commentModelList",commentModelList);
map.put("commentModelList_child",commentModelList_child);
}
}
感謝它工作:) –