-JSONValue失败。 错误是:意外的输入结束

我得到了JSON结果,因为-JSONValue failed. Error is: Unexpected end of input -JSONValue failed. Error is: Unexpected end of input 。 请以正确的方式指导我。

我是解析的新手。 我必须通过POST方法从服务器获取数据。 我有以下细节。 我必须用url传递zip

 {"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]; 

这里的问题是你的post字符串。 使用这一个

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