2012-04-18 69 views
-1

我正在实现SBJSON来从Web服务中获取数据。我在“ConnectionDidFinishLoading”代码如下:错误:JSON无法识别的前导字符

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 failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x686d010 {NSLocalizedDescription=Unrecognised leading character}")

我已经在计算器提到的几个环节,我也使用谷歌找到答案,但我无法获得解决方案

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

Thanx提前...

+2

你的回应字符串是什么? ** NSLog(@“Response String%@”,responseString); **发布它的输出。并且在http://jsonlint.com/上验证你的json字符串。 – Devang 2012-04-18 04:49:58

+0

在浏览器中检查您的网址 – Ayaz 2012-04-18 05:26:40

+0

请参阅此链接:http://stackoverflow.com/questions/5739878/jsonvalue-failed-error-while-fetching-data-from-server-into-iphone。 – 2012-04-18 08:42:37

回答

0

首先你必须调用选择器。

  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); 

    } 
0

我只是有这个问题,它竟然是由Web服务使用的目录权限已经改变。

因此,浏览到WS或尝试使用其他方式访问它以确保它已经启动。