问题描述
|
我正在使用SBJson Parser
这个
我有这个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.
解决方法
我自己解决了,这就是解决的方法...
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类型,然后没有设置内容类型。
, 好吧,我想您可能有一些隐形的非法角色。这也可能是您正在使用的库中的错误。因此,我建议您尝试使用其他库进行解析。如果JSON出了问题,则其他库也应该出现类似的错误。如果其他库没有问题地解析您的JSON,则您可能应该提交SBJSON的错误报告。
我使用JSONKit,它对我来说一直很有效,并且非常易于使用。
, 从您粘贴的内容来看,在JSON启动之前,看起来有些换行符。如果确实是这种情况,则可能是您收到该错误的原因。