iphone - -JSONValue 失败。错误是 : Unexpected end of input

标签 iphone ios json

我得到了 JSON 结果,因为 -JSONValue 失败了。错误是:意外的输入结束。请以正确的方式指导我。

我是解析方面的新手。我必须通过 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];

最佳答案

这里的问题是你的帖子字符串。用这个

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

关于iphone - -JSONValue 失败。错误是 : Unexpected end of input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11432342/

相关文章:

c# - TcpClient应该用于这种情况吗?

ios - Cocoapods/git 'detached HEAD' 状态

iphone - AppDelegate 在类列表中不可用

ios - 将用户交互锁定到 WKWebView

android - 如何删除Facebook "Currently Ineligible for Submission"?

objective-c - 在 Objective-C 中解析嵌套的 JSON 对象

sql - 从表中选择 JSON_VALUE 返回 null 而不是值

javascript - 仅从 Ajax JSON 调用返回特定值

iPhone + 配置文件 + app-info.plist + entitlements.plist = iPhoneApp ?如何 ? entitlemets.plist 到底有什么作用?

iphone - Xcode 4.4,IOS 5.1模拟器。推特框架问题