objective c - How do I test for null in NSDictionary from SBJSON? -


I have found an API that returns a JSON encoded string of data that returns the actual number or the "zero" value Gives in form. As long as JSON has a numerical or string value, everything works as expected, if the key: value pair value is zero, then the code crashes down.

How do I test NSDictionary objectForKey when I am getting a tap from SBJSon?

When the API returns file to the file type , the code below will crash if () on the line.

My purpose - C code tries to test for expected values:

  if (1 == [[Value of WorkForKey: @ "filetype"] integerValue] } {// do something} other {// do something else}   

API JSON output:

  NSOl () is the output of NSDictionary: < / P>   

Code> Tasks {filename = "&" Lt; null & gt; "; Filetype = "& lt; null & gt;"; Tclid = 3; }

When the data from JSON is transferred to the cocoa collection, the class represents Used to do "no value", because the cocoa archive can not contain empty slots & lt; Null & gt; How NSNull prints out

To test for it, you someObject == [NSNull null] . This is a singleton - only one example of code NSNull - indicator comparison works, although you may prefer to follow the normal Coco Comparison Conferences and use the [someObject isKindOfClass Want to: [NSNull class]]] .

You are getting the accident because you are sending integerValue to that NSNull object NSNull integer value does not answer and raises an exception.

Comments