Objective-C: JSON Unrecognised leading character?
when trying to execute little function to get an array using JSON i get the next message:
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDom开发者_开发知识库ain Code=3 \"Unrecognised leading character\" UserInfo=0x5d50e30 {NSLocalizedDescription=Unrecognised leading character}"
This is the code
NSString * payloadAsString = [[NSString alloc] initWithData:receivedData
encoding:NSUTF8StringEncoding];
NSLog(@"%@",payloadAsString);
NSMutableArray *jsonArray = [[NSMutableArray alloc] initWithArray:
[payloadAsString JSONValue]];
self.loginArray = jsonArray;
NSLog prints [["True","1","MTY"]]
(as far as i know it should work).
Any idea?
I'm not sure which version of the json-framework you are using, but I modified the code to print the offending character:
In SBJSONParser.m:
- (BOOL)scanValue:(NSObject **)o
{
...
default:
[self addErrorWithCode:EPARSE description:[NSString stringWithFormat:@"Unrecognised leading character (%x)", c[-1]]];
//[self addErrorWithCode:EPARSE description: @"Unrecognised leading character"];
return NO;
}
You might try setting a breakpoint at that line of code instead.
Also, in general, you can try pasting the JSON into JSONLint at http://jsonlint.com/ to see if it validates. Your JSON does validate, though, so your problem is elsewhere.
Make sure your string values are using a valid straight double quotation mark character. I've seen people try to copy-paste JSON out of an editor only to have their quotes turned into open-quote close-quote pairs like these:
“”
I just had this problem and it turned out to be that the permissions on the directory used by the web service had been changed.
精彩评论