我想获取整套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'终止应用程序,原因:' - [__ NSCFString objectForKeyedSubscript:]:无法识别的选择器发送到实例0xa9f9e90' * 第一次抛出调用堆栈: (0x2f7d012 0x2780e7e 0x30084bd 0x2f6cbbc 0x2f6c94e 0x118646 0x125952 0x126e59 0x2a0053f 0x2a12014 0x2a027d5 0x2f23af5 0x2f22f44 0x2f22e1b 0x2ed77e3 0x2ed7668 0x16c4ffc 0x51d1d 0x3285) libc ++ abi.dylib:terminate调用抛出异常 (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];
答案 0 :(得分:0)
使用NSJSONSerialization:
//getting JSON data from request
NSError *errorJSON = nil
id object = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&errorJSON];
if(!errorJSON){
//JSON parsing success
}
对象将是数组或字典