如何parsing表视图上的API响应?
我的JSON响应数据合成为: –
[{"0":"1","id":"1","1":"Pradeep","name":"Pradeep","2":null,"sender":null,"3":null,"
所以parsing表视图上的“名称”?
我自己的实现是:
我是新的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 }
首先在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。 你想在这里做什么你得到的名字数据的数组。
您需要使用JSONparsing器。 我会推荐: https : //github.com/johnezang/JSONKit
你可以这样做:
JSONDecoder *jsonKitDecoder = [JSONDecoder decoder]; NSError *error = nil; id objectFromJson = [jsonKitDecoder objectWithData:data error:&error];
- MFMailComposeViewController强制图像附件的实际大小
- 如何将video(库中)转换为NSData? 在Swift中
- 什么时候应该从closures的ViewController类中观察持续的Model类调用removeObserver:forKeyPath?
- 将点击事件添加到IOS NSMutableAttributedString
- AVAssetWriter破坏由AVAssetExportSession修剪的video
- 如何在iOS中发送asynchronous发布请求
- 相对约束的自动布局不影响systemLayoutSizeFittingSize:用于UITableViewCell
- 线程安全的UIKit方法
- iOS对象从头开始存档