Note that there are some explanatory texts on larger screens.

plurals
  1. POTouchJSON, dealing with NSNull
    primarykey
    data
    text
    <p>Hi I am using TouchJSON to deserialize some JSON. I have been using it in the past and on those occasions I dealt with occurrences of NSNull manually. I would think the author had to deal with this as well, so me doing that again would just be overhead. I then found this in the documentation:</p> <blockquote> <p>Avoiding NSNull values in output.</p> </blockquote> <pre><code>NSData *theJSONData = /* some JSON data */ CJSONDeserializer *theDeserializer = [CJSONDeserializer deserializer]; theDeserializer.nullObject = NULL; NSError *theError = nil; id theObject = [theDeserializer deserialize:theJSONData error:&amp;theError];} </code></pre> <p>The way I understand it the user of the class can pass a C-style null pointer to the deserializer and when it encounters a NSNull it will insert the values (NULL) passed to it. So later on when I use the values I won't get NSNull, but NULL.</p> <p>This seems strange, the return value is an NSDictionary which can only contain Objects, shouldn't the value default to 'nil' instead?</p> <p><strong>If it is NULL can I check the values like this?</strong></p> <pre><code>if([jsonDataDict objectForKey:someKey] == NULL) </code></pre> <p>It would seem more logically to be able to do this:</p> <pre><code>if(![jsonDataDict objectForKey:someKey]) </code></pre> <p>No to mention all the cases where passing nil is allowed but passing NULL causes a crash.</p> <p><strong>Or can I just pass 'nil' to the deserializer?</strong></p> <p>Much of this stems from me still struggling with nil, NULL, [NSNULL null], maybe I am failing to see the potential caveats in using nil.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload