2012-07-11 51 views
2

我得到的JSON結果爲-JSONValue failed. Error is: Unexpected end of input。請以正確的方式指導我。-JSON值失敗。錯誤是:意外的輸入結束

我是新的解析。我必須通過POST方法從服務器獲取數據。我有以下細節。我必須通過url的郵編

{"zip":"52435","methodIdentifier":"search_dealer"} 

url : http://usaautoleads.com/api.php 

method: post 

web service name: search_dealer 

response : {"success":"0","dealer":[info...]} 

我的代碼在這裏。

NSURL *myURL=[NSURL URLWithString:@"http://usaautoleads.com/api.php"]; 

NSString *post =[[NSString alloc]initWithString:@"52435"]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

[request setURL:myURL]; 

[request setHTTPMethod:@"POST"]; 

[request setHTTPBody:postData]; 

[request setValue:@"application/json" forHTTPHeaderField:@"content-type"]; 

[[NSURLConnection alloc] initWithRequest:request delegate:self]; 
+0

這是你的迴應信息?說清楚... – 2012-07-11 12:17:23

+0

-JSON值失敗。錯誤是:意外的輸入結束 – QueueOverFlow 2012-07-11 12:26:05

+0

@InderKumarRathore我沒有收到我的迴應字符串 – QueueOverFlow 2012-07-11 12:37:51

回答

1

這裏的問題是你的帖子字符串。使用這一個

NSString *zip = @"52435"; 
NSString *methodID = @"search_dealer"; 
NSString *post =[NSString stringWithFormat:@"{\"zip\":\"%@\",\"methodIdentifier\":\"%@\"}", zip, methodID]; 
+0

爲你+1,你是對的..非常感謝您的幫助。 – QueueOverFlow 2012-07-11 13:23:31

相關問題