如何解决上述错误?
我使用下面的代码使用google从地址字符串获取latlong
- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address
{
double latitude = 0.0;
double longitude = 0.0;
NSString *esc_addr = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue];
NSDictionary *resultsDict = [googleResponse valueForKey: @"results"]; // get the results dictionary
NSDictionary *geometryDict = [resultsDict valueForKey: @"geometry"]; // geometry dictionary within the results dictionary
NSDictionary *locationDict = [geometryDict valueForKey: @"location"]; // location dictionary within the geometry dictionary
NSArray *latArray = [locationDict valueForKey: @"lat"];
NSString *latString = [latArray lastObject]; // (one element) array entries provided by the json parser
NSArray *lngArray = [locationDict valueForKey: @"lng"];
NSString *lngString = [lngArray lastObject]; // (one element) array entries provided by the json parser
CLLocationCoordinate2D location;
location.latitude = [latString doubleValue];// latitude;
location.longitude = [lngString doubleValue]; //longitude;
return location;
}在
NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue];行,我得到了错误自动参考计数问题:没有已知的选择器'JSONValue'实例方法
我的项目使用ARC。
如何解决这个错误?
发布于 2013-03-19 12:16:12
JSONValue来自在NSString之上添加的一个类别。为了使用通过类别添加的方法,需要包含相应的标头。在这种情况下,丢失的标题可能是
#import <SBJson/SBJson.h>发布于 2013-03-19 12:13:18
NSString没有一个名为JSONValue的方法(为什么您认为它会呢?)也许您应该使用NSJSONSerialization类将字符串解析为NSDictionary和/或NSArray数据结构。
发布于 2013-03-19 12:28:40
我经历了这个问题..。
执行以下步骤。
1)进入构建阶段->编译源代码。
2)设置与JSON相关的所有文件的标志-fno弧度。
3)清理项目并重新建设。
此错误发生的原因是ARC..as,我们的JSON工具包在使用时具有自动发布功能。不管怎样,希望这能帮到你..。好运!!
https://stackoverflow.com/questions/15499126
复制相似问题