-(NSMutableArray *)stringWithDict:(NSDictionary*)dict{
NSMutableArray *result = [NSMutableArray new];
NSArray*keys = [dict allKeys];
NSArray*sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];//正序
}];
for(NSString*categoryId in sortedArray) {
id value = [dict objectForKey:categoryId];
if([value isKindOfClass:[NSDictionary class]]) {
value = [self stringWithDict:value];
}
[result addObject:value];
// if([str length] !=0) {
//
// str = [str stringByAppendingString:@","];
// }
// str = [str stringByAppendingFormat:@"%@:%@",categoryId,value];
}
NSLog(@"str: %@", result);
return result;
}
key按照升序排序,返回一个排好序的数组。
网友评论