How to parse NSDictionary in an array of arrays?

here is my data template, and I want to create an array of sections, in which case each section will contain an array of strings in this section. I considered the following questions:

and a few other messages, but the result did not work. Can someone tell me how to create an array of sections, and each section should contain its own lines. thanks in advance

EDIT I already parsed my data, the result of the log on the pastebin link is an NSDictionary, this is how I get and analyze it:

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]; 

The result in pastebin is: NSLog(@"Result: %@", result2);

+4
source share
1 answer

Your data is in JSON format, so just use the NSJSONSerialization class to create an array of arrays for you.

 NSString *yourData; NSData *data = [yourData dataUsingEncoding:NSUTF8StringEncoding]; NSArray *arrayOfArrays = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; 

To use an array of partitions in a table view, simply use the usual datasource table datasource :

 // numberOfSectionsInTableView return [array count]; // numberOfRowsInSection return [[array objectAtIndex:section] count]; // cellForRowAtIndexPath cell.textLabel.text = [[[array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:"name"]; 
+1
source

Source: https://habr.com/ru/post/1415913/


All Articles