我从 JSON 提要接收字典数组并将其分配给一个名为 jsonArray 的 NSMutableArray,即:
jsonArray = [deserializedData objectForKey:@"reports"];
提要如下所示:
reports = (
{
address = "The street";
email = "alex@blah.co.uk";
"eng_id" = 1;
"eng_name" = "Alex McPherson";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 59;
lat = "51.1438330";
live = 1;
lng = "0.8693330";
location = "17 Victoria Crescent, Ashford, TN23 7HL";
name = "Alex McPherson";
phone = 01233000000;
rid = "A5C963-C95B-C3D639";
title = "#A5C963-C95B-C3D639, Litter";
tm = "2013-04-28 20:44:20";
type = 5;
"type-text" = "Litter";
},
{
address = "The street";
email = "alex@blah.co.uk";
"eng_id" = 2;
"eng_name" = "Rob Burt";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 122;
lat = "51.1415000";
live = 1;
lng = "0.8715000";
location = "38 Beaver Road, Ashford, TN23 7RP";
name = Alex;
phone = 01233000000;
rid = "5A5C96-9072-6BAFA9";
title = "#5A5C96-9072-6BAFA9, Litter";
tm = "2013-04-28 20:35:56";
type = 8;
"type-text" = "Litter";
};
我想做的是为 key 插入一个新值,让我们在这个 jsonArray 中说:distance = "0.16km" 但我的大脑今晚无法工作......
所以新的 jsonArray 应该看起来像这样,加上上面提到的键值:
reports = (
{
address = "The street";
email = "alex@blah.co.uk";
"eng_id" = 1;
"eng_name" = "Alex McPherson";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 59;
lat = "51.1438330";
live = 1;
lng = "0.8693330";
distance = "0.16km";
location = "17 Victoria Crescent, Ashford, TN23 7HL";
name = "Alex McPherson";
phone = 01233000000;
rid = "A5C963-C95B-C3D639";
title = "#A5C963-C95B-C3D639, Litter";
tm = "2013-04-28 20:44:20";
type = 5;
"type-text" = "Litter";
},
{
address = "The street";
email = "alex@blah.co.uk";
"eng_id" = 2;
"eng_name" = "Rob Burt";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 122;
lat = "51.1415000";
live = 1;
lng = "0.8715000";
distance = "2.13km";
location = "38 Beaver Road, Ashford, TN23 7RP";
name = Alex;
phone = 01233000000;
rid = "5A5C96-9072-6BAFA9";
title = "#5A5C96-9072-6BAFA9, Litter";
tm = "2013-04-28 20:35:56";
type = 8;
"type-text" = "Litter";
};
基本上我有一个计算,从提要中获取 long 和 lat,并计算出 poi 与我当前位置的距离,然后我使用基于我要在上面插入的距离键的排序描述符对数组进行排序。我的代码只是停留在上面的现有 nsmutablearray 中