【问题标题】:Error:JSON unrecognized leading character错误:JSON 无法识别的前导字符
【发布时间】:2012-04-18 04:36:13
【问题描述】:

我正在实现 SBJSON 以从 Web 服务中获取数据。我在“ConnectionDidFinishLoading”中的代码如下:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding];

    NSLog(@"Response String  %@", responseString);

    NSDictionary *results = [responseString JSONValue];

    NSString *extractUsers = [results objectForKey:@"d"];
    NSDictionary *finalResult = [extractUsers JSONValue];
    NSLog(@"Final Results : %@",finalResult);

但我在控制台中收到如下错误消息:

-JSONValue 失败。错误跟踪是:( "错误域=org.brautaset.JSON.ErrorDomain 代码=3 \"无法识别的前导字符\" UserInfo=0x686d010 {NSLocalizedDescription=无法识别的前导字符}" )

我在 stackoverflow 上引用了几个链接,我也使用谷歌找到答案,但我无法获得解决方案

如果您有解决方案,请与我分享。

提前谢谢...

【问题讨论】:

标签: iphone objective-c web-services sbjson


【解决方案1】:

首先你必须调用选择器。

         DownloadManager *mgr= [[DownloadManager alloc] sharedManager:self:@selector(downloadVideos:)];// initialize your class where u write all the methods

              [mgr downloadVideos];  // call method where u send request to particular url
        [mgr autorelease];

    -(void)downloadVideos:(NSMutableData*)data{

          NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

      NSDictionary *parseDict = (NSDictionary*)[responseString JSONValue];

         NSLog(@"%@",parseDict);

     }

【讨论】:

    【解决方案2】:

    我刚遇到这个问题,原来是web服务使用的目录的权限被改变了。

    所以浏览到 WS 或尝试其他访问方式以确保它已启动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 2012-08-28
      • 2015-08-24
      • 1970-01-01
      相关资源
      最近更新 更多