我写了这段代码:
private ArrayList<HashMap<String, HashMap<Integer, String>>> listContent2 = new ArrayList<HashMap<String, HashMap<Integer, String>>>();
public ArrayList<HashMap<String, HashMap<Integer, String>>> content() {
JSONObject json = JSONfunctions.getJSONfromURL("http://...");
try {
JSONArray hotspots = json.getJSONArray("hotspots");
HashMap<String, HashMap<Integer, String>> mapContentHotspot = new HashMap<String, HashMap<Integer, String>>();
for (int i = 0; i < hotspots.length(); i++) {
JSONObject e = hotspots.getJSONObject(i);
JSONArray actions = new JSONArray(e.getString("actions"));
for (int j = 0; j < actions.length(); j++) {
JSONObject e2 = actions.getJSONObject(j);
HashMap<Integer, String> mapContent = new HashMap<Integer, String>();
switch (e2.getInt("activityType")) {
case 27:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
case 2:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
case 1:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
//default:
//break;
}
mapContentHotspot.put(e.getString("id"), mapContent);
}
listContent2.add(mapContentHotspot);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return listContent2;
}
获取此json数组的内容: http://pastebin.com/bXfwcQ2U 问题出在“行动”部分。我尝试使用3“uri”,但我只选择最后一个(使用“activityType”:“1”)。我的java代码在哪里错了? 谢谢!
答案 0 :(得分:0)
你必须添加休息!在你的代码中
case 27:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
break;
case 2:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
break;
case 1:
mapContent.put(e2.getInt("activityType"), e2.getString("uri"));
break;
答案 1 :(得分:0)
也许mapContent的创建应该移到最里面的循环之外。