开发者

What am I missing to decode a JSON bool using JSONKit for IPhone

I have a REST endpoint that returns a BOOL value depending on whether or not the server operation was successful. It returns the response body as simply true or false

When I try to decode the value from the server, I get the following error:

Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'.

I have gone so far as to remove the server response the equation. Now I am just trying to get this code to work:

NSString *result = @"true";
NSNumber *response = [ result objectFromJSONStringWithParseOptions:JKParseOptionNone error:&err ];
if( response == NULL )
    NSLog(@"error: %@", err.localizedDescription );
else
    NSLog( @"%d", ( int )response );

No matter what, I still run into my error condition and print out the error message:

Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'.

What am开发者_开发百科 I missing?


"true" isnt a valid json string


You set your result to the NSString @"true", which is not JSON.

Rather you should get a NSString *response from the server and then apply objectFromJSONStringWithParseOptions:error: to it.

To check valid JSON, try http://jsonlint.com/.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜