I am having trouble trying to sort my NSDictionary in order, and it's been weeks and I still haven't figured it out, so I wish some one could give me a hand here...
NSDictionary data is from JSON and the data is already sorted from the server and it displayed in order in the JSON, but when it retrieved and converted to NSDicitionary, the order is all wrong...
This is the JSON
{
"categories":{
"unknownCategoryName":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName1":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName2":[
{ "key1":"value1",
"key2":"value2"
}],
"unknownCategoryName3":[
{ "key1":"value1",
"key2":"value2"
}]
}
}
The category quantity and its name will not be known until the JSON is received, so this is what I am using to get the count and setting up the tableView and the 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 to list out the section and the section title as the order in the JSON.... rather than a chaos display like
unknownCategory3
unknownCategory1
unknownCategory
unknownCategory2
The "unknownCategory" is Product Category name, they are not in alphabet order, without any number, and they are already sorted and display in order in the JSON...
So, it would be great if you guys could help.
Thanks in advance...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…