所有人......这可能是一个愚蠢的问题,但我是iOS新手..我需要我们的帮助.. 我正在做Json解析..得到一些值..我的json响应是: -
{
"_id" = 6001256351188711607;
"access_level" = private;
createdOn = "2012-12-17T07:06:42.09000";
"created_by" = 9514682679942790960941872227340;
description = "";
keywords = "";
location = (
"12.000023",
"77.000012"
);
picture = "http://54120127762218290878972982207449539830674.jpg";
"rel_interests" = (
);
source = "Bank";
"source_url" = "";
title = ipl;
},
);
"location_description" = "";
picture = "http://54252499650705298384658551818639.jpg";
"rel_interests" = (
);
source = "";
"source_url" = "";
title = "Air";
}
我使用此代码获取标题: -
[titleArray addObject:[[_arrData objectAtIndex:j]valueForKey:@"title"]];
但是当我为位置做这个时我会被抛出异常....我怎么能得到位置? 请帮我实现这个目标......
答案 0 :(得分:0)
您可以使用以下代码获取第一个对象
[titleArray addObject:[[[[_arrData objectAtIndex:j]valueForKey:@"location"]objectAtIndex:0]intValue]];
代表第二个对象
[titleArray addObject:[[[[_arrData objectAtIndex:j]valueForKey:@"location"]objectAtIndex:1]intValue]];
<强>被修改强> 你有一个字典,你有一个多个对象作为数组..在该数组的第一个对象包含一个字典..在该字典中只有你有位置数组。要访问它,您需要按照以下代码
NSArray *location = [[_arrData objectAtIndex:1] objectForKey:@"location"];
double X = [[location objectAtIndex:0] doubleValue];
double locY = [[location objectAtIndex:1] doubleValue];
答案 1 :(得分:0)
title = Watch;
location = (
"12.000000",
"77.000000"
);
假设这是yourDataDict dictionany。
[titleArray addObject:[yourDataDict valueForKey:@"title"];
float loc1 = [[[yourDataDict valueForKey:@"location"] objectAtIndex:0] floatValue];
float loc2 = [[[yourDataDict valueForKey:@"location"] objectAtIndex:1] floatValue];
答案 2 :(得分:0)
NSArray *loc = [[_arrData objectAtIndex:j] objectForKey:@"location"];
double locX = [[loc objectAtIndex:0] doubleValue];
double locY = [[loc objectAtIndex:1] doubleValue];