當我嘗試解析JSON響應,我得到了一個空的響應與此錯誤:我的應用程序沒有解析JSON響應
JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x797c420 {NSLocalizedDescription=Unexpected end of string}"
)
這是我嘗試發送JSON請求和我怎樣努力解析其響應:
發送JSON請求:
- (void)viewWillAppear:(BOOL)animated{
//Specify the adress of the webservice (url)
NSURL *url = [NSURL URLWithString:@"http://xxxxxxxxxxx.com/webservices/"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString *jsonStringArray=[aMutableArray JSONRepresentation];
NSLog(@"-------------");
NSLog(@"%@",jsonStringArray);
NSLog(@"-------------");
[request setPostValue:jsonStringArray forKey:@"liste_des_themes"];
NSLog(@"The response string is: %@",request.responseString);
[request setDelegate:self];
[request startAsynchronous];
}
對於NSLog
這裏我想送它我得到一個正確的JSON格式之前顯示JSON字符串:
NSLog(@"%@",jsonStringArray);//["Mairie","Préfectures et sous-préfectures"]
現在第二NSLog
,我得到空:
NSLog(@"The response string is: %@",request.responseString);//The response string is: (null)
當解析響應:
-(void)requestFinished:(ASIHTTPRequest *)request
{
if(request.responseStatusCode==200)
{
NSLog(@"This block gets called, response code is 200");//This block gets called, response code is 200
//parse the response
NSLog(@"The response string is: %@",request.responseString);
NSString *responseString=[request responseString];
NSDictionary *responseDict=[responseString JSONValue];
}
}
對於NSLog
試圖顯示響應字符串,我什麼也沒得到,既不爲零也不正確:
NSLog(@"The response string is: %@",request.responseString);
//The response string is:
而在這之後,我得到這個錯誤跟蹤:
JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x797c420 {NSLocalizedDescription=Unexpected end of string}"
)
你能幫助我嗎? thanx提前。
對我來說,它看起來像一個服務器端問題 – vikingosegundo