我的json响应数据格式为: -
[{"0":"1","id":"1","1":"Pradeep","name":"Pradeep","2":null,"sender":null,"3":null,"
S解析表视图中的“名称”?
我自己的实现是: -
我是ios开发的新手,请帮帮我
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *allDataDictionary=[NSJSONSerialization JSONObjectWithData:webData
options:0 error:nil]; // response saved in allDataDictionary
NSDictionary *feed=[allDataDictionary objectForKey:@"feed"]; // feeds entry
NSArray *feedforentry=[feed objectForKey:@"entry"];
for(NSDictionary *diction in feedforentry)
{
NSDictionary *title=[diction objectForKey:@"title"];
NSString *label=[title objectForKey:@"label"];
[array addObject:label];
}
[[self JustConfesstable]reloadData]; // reload table
}
答案 0 :(得分:1)
首先在Dictionary中获取数据,然后使用Keys
在NSArray中存储您想要的内容NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];
NSLog(@"%@",json);
NSLog(@"%@",delegate.firstArray);
NSArray * responseArr = json[@"Deviceinfo"];
NSArray * firstarray=[[NSArray alloc]init];
for(NSDictionary * dict in responseArr)
{
[firstarray addObject:[dict valueForKey:@"name"]];
}
第一个数组包含名称..你想从那个json响应。
然后将该数据传递给tablview。你想在这里做什么,你得到了一系列名称数据。
答案 1 :(得分:0)
您需要使用JSON解析器。我会建议:https://github.com/johnezang/JSONKit
你可以这样做:
JSONDecoder *jsonKitDecoder = [JSONDecoder decoder];
NSError *error = nil;
id objectFromJson = [jsonKitDecoder objectWithData:data error:&error];