I'm using SBJson Parser this one
I've this JSON value, it's a valid JSON, but still I get this error
-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"
}
Here's my code, I think I get this JSON error, because I'm not specifying any content type, I'm doing this but still it doesn't work
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];
And this is th开发者_运维知识库e error I receive from the server :
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.
I've solved it myself, this is what solved it ...
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];
As suspected, I was using the wrong HTTPRequest type, and then I was not setting up the content type.
Well, I guess it's possible that you have some invisible illegal character. It's also possible that this is a bug in the library you're using. So I suggest you try parsing it with a differnt library. If there's something wrong with the JSON you should get a similar error with the other library. If the other library parses your JSON without problems you should probably file a bug report for SBJSON.
I use JSONKit and it's always worked great for me and it's really easy to use.
From what you pasted it's looking like there are some newline chars before your JSON starts. If this is actually the case, it could be why you're getting that error.
精彩评论