我有一个名为 NSMutableArrayallItems
其中有以下内容ProductData
目的。
每个对象都有cid, cname, ctype
and cimage
。正如您在下面看到的,json 对象没有按顺序出现。然而,cid
是一个排序指标。
我想知道如何根据cid订购?
[
{
"cid": "2",
"cname": "Meats",
"ctype": "main",
"cimage": "baked_chicken.jpg"
},
{
"cid": "1",
"cname": "Dips",
"ctype": "side",
"cimage": "stuffed_eggplant.jpg"
},
{
"cid": "4",
"cname": "Sandwiches",
"ctype": "sand",
"cimage": "chickenshawarma.jpg"
},
{
"cid": "3",
"cname": "Appetizers",
"ctype": "side",
"cimage": "rice_lentils.jpg"
},
{
"cid": "5",
"cname": "Desserts",
"ctype": "dsrt",
"cimage": "cake.jpg"
}]
如果我使用sortDescriptior
,它部分有效。我面临的问题,排序时,它首先显示cid
1 然后cid
10 然后cid
2.
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"cid" ascending:YES];
[allItems sortUsingDescriptors:@[sortDescriptor]];