-2

我想获取整组 JSON 数据的纬度和经度值:

          {
            branches =             (
                                {
                    city = "Las Vegas";
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "3.35";
                    distanceInMiles = "2.08";
                    id = 15739653;
                    latitude = "36.029102";
                    longitude = "-115.114960";
                    name = "Las Vegas - 89123";
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "8876 Eastern Avenue";
                    telephone = "";
                }
            );
            id = 355896;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net";
            name = "Body Heat";
        },
                {
            branches =             (
                                {
                    city = "Las Vegas";
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "18.09";
                    distanceInMiles = "11.24";
                    id = 6043133;
                    latitude = "36.143978";
                    longitude = "-115.280380";
                    name = "Las Vegas - 8645 W Sahara Ave.";
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "8645 W Sahara Ave.";
                    telephone = "";
                }
            );
            id = 121022;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net/31513.jpg";
            name = "Just Face It Medspa";
        },
                {
            branches =             (
                                {
                    city = Henderson;
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "3.66";
                    distanceInMiles = "2.27";
                    id = 4563174;
                    latitude = "35.997353";
                    longitude = "-115.120628";
                    name = Henderson;
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "3035 W Horizon Ridge Pkwy., Suite 100";
                    telephone = "";
                }
            );
            id = 57146;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net/31513.jpg";
            name = "Signature Institute of Aesthetic Sculpting";
        },
                {
            branches =             (
                                {
                    city = "Las Vegas";
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "9.71";
                    distanceInMiles = "6.03";
                    id = 13769564;
                    latitude = "36.106091";
                    longitude = "-115.166840";
                    name = "Las Vegas - 89109";
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "145 East Harmon Avenue";
                    telephone = "";
                }
            );
            id = 272131;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net";
            name = "Luxury Suites International";
        },
                {
            branches =             (
                                {
                    city = "Las Vegas";
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "25.24";
                    distanceInMiles = "15.68";
                    id = 10385118;
                    latitude = "36.238758";
                    longitude = "-115.224167";
                    name = Northwest;
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "5803 W Craig Rd., Suite 104";
                    telephone = "";
                },
                                {
                    city = "Las Vegas";
                    country = "United States";
                    countryIsoCode = USA;
                    distanceInKms = "5.65";
                    distanceInMiles = "3.51";
                    id = 9391473;
                    latitude = "36.067402";
                    longitude = "-115.172226";
                    name = "Posare Salon Town Square";
                    state = Nevada;
                    stateIsoCode = NV;
                    street = "6569 S Las Vegas Blvd.";
                    telephone = "";
                }
            );
            id = 216657;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net";
            name = "Posare Salons";
        }
    );
    owners =     (
                {
            id = 1;
            logoUrl = "http://d2bvnbhf12ry1m.cloudfront.net/media/1830.gif";
            name = OneBigPlanet;
            type = group;
        }
    );

我该怎么做?我尝试过使用以下内容,但它不断返回错误说

GoogleAnalytics 2.0b4 void GAIuncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:41):未捕获的异常:-[__NSCFString objectForKeyedSubscript:]:无法识别的选择器发送到实例 0xa9f9e90 2013-09-09 14:24:46.851 * 由于未捕获的异常而终止应用程序'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0xa9f9e90' * First throw call stack: (0x2f7d012 0x2780e7e 0x30084bd 0x2f6cbbc 0x2f6c94e 0x118646 0x125952 0x126e59 0x2a0053f 0x2a12014 0x2a027d5 0x2f23af5 0x2f22f44 0x2f22e1b 0x2ed77e3 0x2ed7668 0x16c4ffc 0x51d1d 0x3285) libc+ +abi.dylib: 终止调用抛出异常 (lldb)

我只是想获取所有经度和纬度以将其存储为 doubleValue,然后将这些点绘制到地图上。有任何想法吗?

 NSURL *url = [[NSURL alloc] initWithString:@"http://api.onebigplanet.com/ws/local-daily-deals?wsToken=&wsVersion=3.0.0&categoryId=1&categoryId=2&numItems=0&out=json&sort=distance&zipCode=89123&radiusInMiles=100&latitude&longitude"];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation
                                         JSONRequestOperationWithRequest:request
                                         success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                                             NSLog(@"%@",JSON);
                                             self.mapLocations = JSON;
                                             for(NSDictionary *locations in self.mapLocations) {
                                                 //NSLog(@"%@",locations[@"merchants"][0][@"branches"][0][@"latitude"]);
                                                 NSLog(@"Latitude: %@", locations);
                                             }

                                         } failure:^(NSURLRequest *request, NSHTTPURLResponse *response,
                                                     NSError *error, id JSON) {
                                             NSLog(@"NSError: %@",error.localizedDescription);
                                         }];

    [operation start];
4

1 回答 1

0

使用 NSJSONSerialization:

//getting JSON data from request
NSError *errorJSON = nil
id object = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&errorJSON];
if(!errorJSON){
    //JSON parsing success
}

对象将是数组或字典

于 2013-09-10T08:25:58.057 回答