【发布时间】:2014-11-10 09:04:08
【问题描述】:
我想将 JSON 数据加载到带有字幕和图像的列表视图中(行的左侧)。
我在下面发布了我的示例 JSON 响应代码:
for (int i = 0; i < contacts.length(); i++) {
JSONObject obj = contacts.getJSONObject(i);
Iterator keys = obj.keys();
while(keys.hasNext()) {
// loop to get the dynamic key
String currentDynamicKey = (String)keys.next();
// store key in an arraylist which is A,B,...
// get the value of the dynamic key
JSONArray currentDynamicValue = obj.getJSONArray(currentDynamicKey);
Log.d("Response: ", "> " + currentDynamicKey);
int jsonrraySize = currentDynamicValue.length();
if(jsonrraySize > 0) {
for (int ii = 0; ii < jsonrraySize; ii++) {
JSONObject nameObj = currentDynamicValue.getJSONObject(ii);
String name = nameObj.getString("name");
System.out.print("Name = " + name);
//Log.d("Response: ", "> " + name);
//store name in an arraylist
}
}
}
}
我想显示Tittle : currentDynamicKey 值和Sub Title : Name 字符串值。
【问题讨论】:
-
试试 google 有很多例子
-
哇你们太棒了。非常感谢!
标签: android json android-listview