2012-09-02 26 views
0

我是JSON解析的新手。我正在使用SBJson 3.1,並試圖獲取數據以應對我所遇到的錯誤。我在谷歌上搜索了很多,但沒有人問過或解釋實際上錯誤Illegal Start of Token的含義。所以請能有人解釋我這個?我該如何調試這個錯誤?JSON值失敗。錯誤是:令牌非法啓動[<]

到目前爲止我寫的代碼是:

-(IBAction) Start:(id)sender 
{ 
responseData = [[NSMutableData data] retain]; 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]]; 

    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
} 

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
[responseData setLength:0]; 
} 

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
[responseData appendData:data]; 
} 

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]]; 

[connection release]; 
responseData = nil; 
} 

-(void) connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
[connection release]; 

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

[responseData release]; 

NSDictionary *dict = [responseString JSONValue]; 

} 
+0

什麼是你的JSON輸入? –

+0

我只是提供URL「xyz/Final/webserviceName.php」來獲取整個數據以用於測試目的。 – NightFury

+0

哦,是的,我完全可以用它來告訴你問題是什麼。如何告訴我什麼是數據? –

回答

1

首先代替:

#define URL @"http://xyz...." 

和使用它作爲,

的NSURLRequest *請求= [的NSURLRequest requestWithURL: [NSURL URLWithString:URL]];

我只是它複製到:

的NSURLRequest *請求= [的NSURLRequest requestWithURL:[NSURL URLWithString:HTTP:// XYZ ....]];

其次,問題是通過web服務返回的json字符串不正確。當我打印的響應數據,它是這樣的:

<3c68746d 6c3e0a20 2020203c 68656164 3e0a2020 20203c2f 68656164 3e0a2020 20203c62 6f64793e 0a5b7b22 55736572 4964223a 2231222c 22557365 724e616d 65223a22 4d616861 20497a68.....>

This鏈接幫助我很多理解什麼是「令牌的非法啓動」的意思。

Web服務,下面寫的是:

<html><head></head><body>[ 
{ 
    "UserId": "1", ..... 

錯誤提出的是:

Parse error on line 1: <html><head></head>< ^ Expecting '{', '['