1

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?

kevboh
  • 5,207
  • 5
  • 38
  • 54
sarunw
  • 8,036
  • 11
  • 48
  • 84

3 Answers3

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
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
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