我可以获取JSON对象并将其显示,但我该如何从“lat”和“lng”中获取值以在Xcode中使用?
我的代码:
NSString *str=[NSString stringWithFormat:@"https://www.<WEBSITE>];
NSURL *url=[NSURL URLWithString:str];
NSData *data=[NSData dataWithContentsOfURL:url];
NSError *error=nil;
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSLog(@"Your JSON Object: %@ Or Error is: %@", dictionary, error);
JSON对象:
(
{
response = {
lat = "52.517681";
lng = "-115.113995";
};
}
我似乎无法访问任何数据。我已经尝试过:
NSLog(@"Value : %@",[dictionary objectForKey:@"response"]);
我也尝试了很多变化,比如:
NSLog(@"Value : %@",[[dictionary objectForKey:@"response"] objectForKey:@"lat"]);
但最终总是会崩溃:
-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15dd8b80
我注意到在调试过程中,“字典”只包含一个对象。如何将我的JSON对象转换为具有键值对的NSDictionary?这个JSON对象是格式错误还是其他什么问题?