我正在从JSON
Web服务中解析数据,然后使用以下代码按价格、日期、折扣等对数据进行排序。
这是我用来排序数据的代码:
-(void)priceSort:(id)sender {
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey: @"price" ascending: YES];
NSMutableArray *sortedArray = (NSMutableArray *)[self.displayItems
sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortDescriptor]];
[self setDisplayItems:sortedArray];
[self.tableView reloadData];
}
这段代码在按价格排序时可以正常工作,但是当我想按评论数量排序时,似乎无法正确使用这段代码:
对于价格,我使用以下代码:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey: @"price" ascending: YES];
但是对于评论,我想要获取“n”值。请查看它如何嵌套在下面的可变数组“display Items”的输出中:
"old_price" = 24;
price = "9.9";
reviews = {
**n = 11;**
val = 70;
};
"sold_count" = 101;
感谢您的帮助:)