I want to parse a C string into an NSDictionary. The following code works great when compiled under OS X, but leads to an error "JSON Parse error" when used under Ubuntu 14.04 LTS with GNUStep 7.7. The error only occurs for bool values (true,false), but works for numbers and strings.
Do you have any idea what the problem might be or how I can circumnavigate it?
#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;
}
I found the solution: it was a bug in the GNUstep version I was using, when using the latest source of
NSJSONSerialization
, everything works fine.