I had problems sorting my NSDictionary in order, and it has been weeks, and I still haven’t figured it out, so I would like someone to give me a hand here ...
NSDictionary data is taken from JSON, and the data is already sorted from the server and displayed in JSON in order, but when it is retrieved and converted to NSDicitionary, the order is all wrong ...
This is json
{
"categories":{
"unknownCategoryName":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName1":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName2":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName3":[
{ "key1":"value1",
"key2":"value2"
}]
}
}
The number of categories and its name will not be known until JSON is received, so this is what I use to get the counter and set up the View table and section
NSDictionary *results = [jsonString JSONValue];
NSDictionary *all = [results objectForKey:@"categories"];
self.datasource = all;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.datasource count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *title = [[self.datasource allKeys] objectAtIndex:section];
return title;
}
And what I want to do is list the section and section title as an order in JSON ... and not display chaos, for example
unknownCategory3
unknownCategory1
unknownCategory
unknownCategory2
"unknownCategory" - , , - , JSON...
, , , , .
...