Objective c 使用GNUStep将JSON解析到NSDictionary中不适用于布尔值
我想将C字符串解析到NSDictionary中。下面的代码在OSX下编译时效果很好,但在Ubuntu14.04LTS和Gnustep7.7下使用时会导致JSON解析错误。该错误仅适用于布尔值true、false,但适用于数字和字符串 你知道问题可能是什么,或者我怎样才能绕过它吗Objective c 使用GNUStep将JSON解析到NSDictionary中不适用于布尔值,objective-c,json,linux,gnustep,Objective C,Json,Linux,Gnustep,我想将C字符串解析到NSDictionary中。下面的代码在OSX下编译时效果很好,但在Ubuntu14.04LTS和Gnustep7.7下使用时会导致JSON解析错误。该错误仅适用于布尔值true、false,但适用于数字和字符串 你知道问题可能是什么,或者我怎样才能绕过它吗 #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { NSAutoreleasePool *pool
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//const char* str = "{\"result\":\"foo\"}"; //works
const char* str = "{\"result\":true}"; //doesn't work
NSData* data = [NSData dataWithBytes:str length:strlen(str)];
NSError *err = nil;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
if(err != nil)
//Output: "Err: JSON Parse error"
NSLog(@"Err: %@",err);
else
NSLog(@"Dic: %@",dic);
[pool drain];
return 0;
}
我找到了解决方案:这是我使用的GNUstep版本中的一个bug,当使用NSJSONSerialization时,一切正常。从哪里得到错误?JSON看起来像什么?@HotLicks我将JSON放入上面的示例{result:true}。调用[NSJSONSerialization JSONObjectWithData]时发生错误,并且设置了err输出:err:JSON Parse error