2012-04-18 60 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或嘗試使用其他方式訪問它以確保它已經啓動。