本文介绍了-JSONValue失败.错误是:意外的输入结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got the JSON result as -JSONValue failed. Error is: Unexpected end of input. Please direct me in right way.

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

I am new in parsing . I have to get Data from the server by POST method. I have following details. I have to pass zip with 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];

推荐答案

问题出在您的帖子字符串上.使用这个

The problem here is with your post string. Use this one

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

这篇关于-JSONValue失败.错误是:意外的输入结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 23:30