-6

你们所有人......这可能是一个愚蠢的问题,但我是 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"]];

但是当我为位置执行此操作时,我会抛出异常......我怎样才能获得位置?请帮助我实现这一目标...

4

3 回答 3

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];
于 2012-12-24T09:07:12.887 回答
0
title = Watch;
location =         (
            "12.000000",
            "77.000000"
        );

假设这是 yourDataDict 字典。

[titleArray addObject:[yourDataDict valueForKey:@"title"];
float loc1 = [[[yourDataDict valueForKey:@"location"] objectAtIndex:0] floatValue];
float loc2 = [[[yourDataDict valueForKey:@"location"] objectAtIndex:1] floatValue];
于 2012-12-24T09:09:35.277 回答
0
NSArray *loc = [[_arrData objectAtIndex:j] objectForKey:@"location"];
double locX = [[loc objectAtIndex:0] doubleValue];
double locY = [[loc objectAtIndex:1] doubleValue];
于 2012-12-24T09:10:33.847 回答