This is the JSON, it shows by descending order, id_no
{"users":[ {"id_no":"501", "type":"User", "country":"United Kingdom", "city":"London" } {"id_no":"500", "type":"Admin", "country":"United States", "city":"San Fransisco"} ]
This is my code :
- (void)viewDidLoad { [super viewDidLoad]; NSURL *jsonURL = [NSURL URLWithString:@"http://example.com/sohw.php"]; NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL]; NSError *error = nil; NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; self.reports = [dataDictionary objectForKey:@"users"]; }
What I want to do is to sort users in descending order when displayed on the tableView as per as the JSON file.
I have already got answers such as : Best way to sort an NSArray of NSDictionary objects?
or :
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES]; stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; recent = [stories copy];
but when I tried to implement it, it does not worked for me according to my current structure of code.
Can you please guide me on how I can solve it, according to the code I provided ?
users?viewDidLoad!