首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >没有已知的选择器“JSONValue”实例方法

没有已知的选择器“JSONValue”实例方法
EN

Stack Overflow用户
提问于 2013-03-19 12:09:37
回答 4查看 1.6K关注 0票数 1

如何解决上述错误?

我使用下面的代码使用google从地址字符串获取latlong

代码语言:javascript
运行
复制
- (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;
}

代码语言:javascript
运行
复制
NSDictionary *googleResponse = [[NSString stringWithContentsOfURL: [NSURL URLWithString: req] encoding: NSUTF8StringEncoding error: NULL] JSONValue];

行,我得到了错误自动参考计数问题:没有已知的选择器'JSONValue'实例方法

我的项目使用ARC。

如何解决这个错误?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-03-19 12:16:12

JSONValue来自在NSString之上添加的一个类别。为了使用通过类别添加的方法,需要包含相应的标头。在这种情况下,丢失的标题可能是

代码语言:javascript
运行
复制
#import <SBJson/SBJson.h>
票数 3
EN

Stack Overflow用户

发布于 2013-03-19 12:13:18

NSString没有一个名为JSONValue的方法(为什么您认为它会呢?)也许您应该使用NSJSONSerialization类将字符串解析为NSDictionary和/或NSArray数据结构。

票数 2
EN

Stack Overflow用户

发布于 2013-03-19 12:28:40

我经历了这个问题..。

执行以下步骤。

1)进入构建阶段->编译源代码。

2)设置与JSON相关的所有文件的标志-fno弧度。

3)清理项目并重新建设。

此错误发生的原因是ARC..as,我们的JSON工具包在使用时具有自动发布功能。不管怎样,希望这能帮到你..。好运!!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15499126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档