我想将JSON数据加载到带有字幕和图像的List视图中(行的左侧)。
下面我发布了我的示例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
字符串值。
答案 0 :(得分:0)
如果您已经拥有数据并且不一定需要将服务器请求与适配器集成,那么您实际上只需要一个支持JSONArray的适配器。 Advanced-Adapters库中有一个非常好的开源软件。然后,只需将JSONArray传递给适配器并将适配器设置为ListView
。