【发布时间】:2018-01-04 09:31:53
【问题描述】:
我想按 location_name 对嵌套的 Json 数组进行排序,我的 json 在 nsdictionary 中
Json 数组是
apiResult:{
Description = "List of Location";
code = 200;
locationList = (
{
"location_id" = 481;
"location_name" = "<null>";
"pre_fixied" = "$3.00";
"state_name" = Melbourne;
status = 0;
zone = "Zone 2";
"zone_id" = 30;
},
{
"location_id" = 461;
"location_name" = "O'Halloran Hill";
"pre_fixied" = "$5.00";
"state_name" = Adelaide;
status = 1;
zone = "Zone 3";
"zone_id" = 31;
},
{
"location_id" = 460;
"location_name" = "Sheidow Park";
"pre_fixied" = "$5.00";
"state_name" = Adelaide;
status = 1;
zone = "Zone 3";
"zone_id" = 31;
},
{
"location_id" = 459;
"location_name" = "Hallett Cove";
"pre_fixied" = "$5.00";
"state_name" = Adelaide;
status = 1;
zone = "Zone 3";
"zone_id" = 31;
},
{
"location_id" = 458;
"location_name" = "Eden Hills";
"pre_fixied" = "$5.00";
"state_name" = Adelaide;
status = 1;
zone = "Zone 3";
"zone_id" = 31;
},
{
"location_id" = 457;
"location_name" = Glengowrie;
"pre_fixied" = "$5.00";
"state_name" = Adelaide;
status = 1;
zone = "Zone 3";
"zone_id" = 31;
}
);
message = "List of Location";
status = Success;
}
它按位置 id 降序出现我希望这个 json 按位置名称升序排列。 我有单独排序位置列表数组,但我想要整个 json 和 locationlist 按位置名称顺序
【问题讨论】:
-
对整个 json 进行排序而不是仅对 locationList 进行排序有什么意义吗?因为我认为您只需要对 locationList 列表数组进行排序。
-
但是我需要整个 json 来传递另一个页面
-
整个json意味着你需要
Description = "List of Location";code = 200;message = "List of Location";status = Success;这些都在另一个页面? -
是的,采用 NsMutableDictionary 格式
-
然后创建另一个字典,对位置数组进行排序后,在该字典中添加
Description、code、message、status和sortedArray
标签: ios objective-c arrays json sorting