Objective-C:JSON无法识别的主角? [英] Objective-C: JSON Unrecognised leading character?
问题描述
当尝试使用JSON执行小函数来获取数组时,我得到下一条消息:
when trying to execute little function to get an array using JSON i get the next message:
-JSONValue失败。错误跟踪是:(
错误域= org.brautaset.JSON.ErrorDomain代码= 3 \无法识别的前导字符\UserInfo = 0x5d50e30 {NSLocalizedDescription =无法识别的前导字符}
这是代码
NSString * payloadAsString = [[NSString alloc] initWithData:receivedData
encoding:NSUTF8StringEncoding];
NSLog(@"%@",payloadAsString);
NSMutableArray *jsonArray = [[NSMutableArray alloc] initWithArray:
[payloadAsString JSONValue]];
self.loginArray = jsonArray;
NSLog打印 [[True,1,MTY]]
(据我所知它应该有效)。
NSLog prints [["True","1","MTY"]]
(as far as i know it should work).
任何想法?
推荐答案
我不确定您使用的是哪个版本的json-framework,但我修改了代码以进行打印有问题的人物:
I'm not sure which version of the json-framework you are using, but I modified the code to print the offending character:
在SBJSONParser.m中:
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.
此外,一般情况下,您可以尝试通过 http://将JSON粘贴到JSONLint中jsonlint.com/ 查看它是否有效。但是,您的JSON确实可以验证,因此您的问题出在其他地方。
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.
这篇关于Objective-C:JSON无法识别的主角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!