I'm using SBJson to parse some JSON result from a webservice. The problem is I'm not sure how SBJson handles boolean types. The service returns it as a true or false value; is this handled automatically in SBJson or do I have to detect it myself?
Asked
Active
Viewed 1,460 times
3 Answers
2
Coming from Java, this confused me too (both lack of a real Boolean and how SBJson represents); 2nd BOOL example, of course, doesn't work:
BOOL bDir = ((NSNumber*)[obj objectForKey:@"isDirectory"]).intValue;
//BOOL bDir = [obj objectForKey:@"isDirectory"];
type = bDir ? MI_DIRECTORY : MI_FILE;

bassetbob
- 131
- 1
- 3
-
Try `BOOL bDir = [[obj objectForKey:@"isDirectory"] boolValue];` – Stig Brautaset Dec 12 '12 at 16:22
1
Might I suggest you check out the class documentation: http://json-framework.googlecode.com/svn/trunk/documentation/interfaceSBJSON.html
I believe SBJson returns booleans as NSNumbers set to either 0 or 1 which you can use a boolean values for things like if statements. Or you could always just get the boolValue
for a true BOOL
type

cpjolicoeur
- 12,766
- 7
- 48
- 59
-
Updated link for that documentation: http://stig.github.com/json-framework/api/3.1/json2objc.html – Stig Brautaset Dec 12 '12 at 16:20
0
It's working as @cpjolicoeur mentioned.
Working example:
NSDictionary *response = [responseString JSONValue]
BOOL example = [[response objectForKey:@"example"] boolValue]
if(example) {
......

Vojtech Vrbka
- 5,342
- 6
- 44
- 63