首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone,SBJSON错误

iPhone,SBJSON错误
EN

Stack Overflow用户
提问于 2011-05-27 23:35:07
回答 3查看 2.3K关注 0票数 0

我使用的是SBJson解析器this one

我有这个JSON值,它是一个有效的JSON,但我仍然收到这个错误

代码语言:javascript
复制
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x63726a0 {NSLocalizedDescription=Unrecognised leading character}"


{
"Account": {
    "LoginName": "My Name",
    "Name": "My Name"
},
"UseInvoiceAddressAsDeliveryAddress": "true",
"InvoiceAddress": {
    "Zip": "16444",
    "CountryId": "1",
    "City": "SSSS",
    "Line2": "8",
    "Line1": "Street 4"
},
"Phone": "12345678",
"FirstName": "My",
"LastName": "Name",
"Email": "sample@example.com",
"CellPhone": "234254233"
}

这是我的代码,我想我得到了这个JSON错误,因为我没有指定任何内容类型,我正在这样做,但它仍然不起作用

代码语言:javascript
复制
    SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *jsonConvertedObj = [writer stringWithObject:customerObject];
NSLog(@"The converted JSON String .... %@",jsonConvertedObj);
NSData *postData = [jsonConvertedObj dataUsingEncoding:NSASCIIStringEncoding];  
NSMutableData *myMutablePostData = [NSMutableData dataWithData:postData];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:myURL];
[request setRequestMethod:@"POST"];
[request setClientCertificateIdentity:identity];
[request setValidatesSecureCertificate:NO];
[request addData:myMutablePostData withFileName:@"" andContentType:@"application/json" forKey:@""];
[request startSynchronous];

这是我从服务器收到的错误:

代码语言:javascript
复制
The server encountered an error processing the request. The exception message is 'The     incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml'; 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-29 06:46:14

我自己解决了它,这就是解决它的方法...

代码语言:javascript
复制
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:myURL];
[request setPostBody:myMutablePostData];
[request setRequestMethod:@"POST"];
[request setClientCertificateIdentity:identity];
[request setValidatesSecureCertificate:NO];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request setDelegate:self];
[request startSynchronous];

正如怀疑的那样,我使用了错误的HTTPRequest类型,然后我没有设置内容类型。

票数 1
EN

Stack Overflow用户

发布于 2011-05-27 23:59:36

好吧,我猜你可能有一些看不见的非法角色。这也可能是您正在使用的库中的错误。所以我建议你试着用不同的库来解析它。如果JSON有问题,你应该在其他库中得到一个类似的错误。如果其他库解析您的JSON没有问题,那么您可能应该为SBJSON提交一份错误报告。

我使用JSONKit,它对我来说一直都很好用,而且它真的很容易使用。

票数 0
EN

Stack Overflow用户

发布于 2011-05-28 00:02:43

从你粘贴的内容来看,在你的JSON开始之前,看起来有一些换行符。如果这真的是这样的话,这可能就是你得到这个错误的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6154523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档