如何在一个数组中获取此响应

时间:2013-11-29 03:45:15

标签: objective-c

这是我从网络服务获得的回复。如何只获取城市记录?

  Data =     (
                    {
                Cities =             (
                                    {
                        CityCode = 21;
                        Name = Cork;
                        Numbers =                     (
                                                    {
                                Number = 2349990;
                                PauseOne = 3;
                                PauseTwo = 3;
                            }`enter code here`
                        );
                    }
    )

3 个答案:

答案 0 :(得分:0)

NSDictionary *cities = myJson[@"Data"][0][@"Cities"][0];

NSLog(@"City Name is = %@", cities[@"Name"]);
NSLog(@"City Code is = %d", [cities[@"CityCode"] intValue]);

答案 1 :(得分:0)

此代码最终用于您:

NSMutableArray *arrFinalAllCities = [[NSMutableArray alloc]init];
    NSMutableArray *arrData = [responseObject objectForKey:@"Data"];
    for (int a=0; a<arrData.count; a++)
    {
        NSMutableArray *arrCity = [[arrData objectAtIndex:a] objectForKey:@"Cities"];
        for (int b=0; b<arrCity.count; b++)
        {
            [arrFinalAllCities addObject:[arrCity objectAtIndex:b]];
        }
    }
    NSLog(@"%@",arrFinalAllCities);

答案 2 :(得分:-1)

你发布的响应看起来像nsdictionary。不是服务器返回json。你可以发布服务器返回的确切json吗?提示:将nsdata转换为nsstring并发布dat