Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I've just woke up this morning with a good solution. What about this:</p> <p>Serialize the JSON using the option to receive Mutable Arrays and Dictionaries:</p> <pre><code>NSMutableDictionary *rootDict = [NSJSONSerialization JSONObjectWithData:_receivedData options:NSJSONReadingMutableContainers error:&amp;error]; ... </code></pre> <p>Get a set of keys that have <code>[NSNull null]</code> values from the leafDict:</p> <pre><code>NSSet *nullSet = [leafDict keysOfEntriesWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id key, id obj, BOOL *stop) { return [obj isEqual:[NSNull null]] ? YES : NO; }]; </code></pre> <p>Remove the filtered properties from your Mutable leafDict:</p> <pre><code>[leafDict removeObjectsForKeys:[nullSet allObjects]]; </code></pre> <p>Now when you call <code>fight.winnerID = [dict objectForKey:@"winner"];</code> winnerID is automatically going to be <code>(null)</code> or <code>nil</code> as opposed to <code>&lt;null&gt;</code> or <code>[NSNull null]</code>.</p> <p>Not relative to this, but I also noticed that it is better to use a <code>NSNumberFormatter</code> when parsing strings to NSNumber, the way I was doing was getting <code>integerValue</code> from a nil string, this gives me an undesired NSNumber of <code>0</code>, when I actually wanted it to be nil.</p> <p>Before:</p> <pre><code>// when [leafDict valueForKey:@"round"] == nil fight.round = [NSNumber numberWithInteger:[[leafDict valueForKey:@"round"] integerValue]] // Result: fight.round = 0 </code></pre> <p>After:</p> <pre><code>__autoreleasing NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init]; fight.round = [numberFormatter numberFromString:[leafDict valueForKey:@"round"]]; // Result: fight.round = nil </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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