here 是我的数据模式,我想创建一个节数组,在这种情况下,每个节将包含该节中的一个行数组。我看了以下问题:
和其他一些帖子,但没有结果。任何人都可以指导我如何创建一系列部分,每个部分都应包含自己的行..提前致谢
编辑
我已经解析了我的数据,pastebin链接处的日志结果是一个NSDictionary
这是我获取和解析它的方式:
NSString*key1=[ result objectForKey:@"key" ];
NSString *s1=[@"http://" stringByAppendingString:server.text];
NSString *s2=[s1 stringByAppendingString:@"/ipad/button.php"];
NSURL *url2=[NSURL URLWithString:[s2 stringByAppendingString:[@"?key=" stringByAppendingString:key1]]];
NSData *data2=[NSData dataWithContentsOfURL:url2];
result2=[NSJSONSerialization JSONObjectWithData:data2 options:NSJSONReadingMutableContainers error:nil];
pastebin 的结果是这样的:
NSLog(@"Result: %@", result2);
最佳答案
您的数据采用 JSON 格式,因此只需使用 NSJSONSerialization
类为您创建数组数组。
NSString *yourData;
NSData *data = [yourData dataUsingEncoding:NSUTF8StringEncoding];
NSArray *arrayOfArrays = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments error:nil];
要在表 View 中使用您的部分数组,只需使用通常的表 View
datasource
方法:// numberOfSectionsInTableView
return [array count];
// numberOfRowsInSection
return [[array objectAtIndex:section] count];
// cellForRowAtIndexPath
cell.textLabel.text = [[[array objectAtIndex:indexPath.section]
objectAtIndex:indexPath.row]
objectForKey:"name"];
关于objective-c - 如何将 NSDictionary 解析为数组数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10878215/