获取JSON记录JSON:
{
content : [
{ action : "eat ice-cream", username : "tom" },
{ action : "play sport", username : "mike" },
{ action : "dancing", username : "dan" }
],
message : "OK",
status : 1
}
iPhone: Object将包含一个action和username字段。 在回调函数中
-(void) fetchdatacompleted:(NSDictionary*)dict
{
if([dict objectForKey:@"content"] != nil)
{
[objectArray removeAllObjects];
if([[dict objectForKey:@"content"] isKindOfClass:[NSArray class]])
{
NSArray *array = (NSArray *)[dict objectForKey:@"content"];
for (NSDictionary *dict in array)
{
myobject = [[Object alloc] initWithDict:dict];
[objectArray addObject:myobject];
}
}
}
}
Android如何处理上述处理?
答案 0 :(得分:1)
示例:
JSONObject json = new JSONObject(jsonString);
JSONArray content = json.JSONArray("content");
for (int i = 0; i < content.length(); i++) {
JSONObject entry = content.getJSONObject(i);
// and so on...
}