我使用的是SBJson解析器this one
我有这个JSON值,它是一个有效的JSON,但我仍然收到这个错误
-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错误,因为我没有指定任何内容类型,我正在这样做,但它仍然不起作用
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];这是我从服务器收到的错误:
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.发布于 2011-05-29 06:46:14
我自己解决了它,这就是解决它的方法...
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类型,然后我没有设置内容类型。
发布于 2011-05-27 23:59:36
好吧,我猜你可能有一些看不见的非法角色。这也可能是您正在使用的库中的错误。所以我建议你试着用不同的库来解析它。如果JSON有问题,你应该在其他库中得到一个类似的错误。如果其他库解析您的JSON没有问题,那么您可能应该为SBJSON提交一份错误报告。
我使用JSONKit,它对我来说一直都很好用,而且它真的很容易使用。
发布于 2011-05-28 00:02:43
从你粘贴的内容来看,在你的JSON开始之前,看起来有一些换行符。如果这真的是这样的话,这可能就是你得到这个错误的原因。
https://stackoverflow.com/questions/6154523
复制相似问题