Checking a null value in Objective-C that has been returned from a JSON string

前端 未结 15 1593
北海茫月
北海茫月 2020-11-30 20:34

I have a JSON object that is coming from a webserver.

The log is something like this:

{          
   \"status\":\"success\",
   \"Us         


        
15条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 21:05

    Best would be if you stick to best practices - i.e. use a real data model to read JSON data.

    Have a look at JSONModel - it's easy to use and it will convert [NSNUll null] to * nil * values for you automatically, so you could do your checks as usual in Obj-c like:

    if (mymodel.Telephone==nil) {
      //telephone number was not provided, do something here 
    }
    

    Have a look at JSONModel's page: http://www.jsonmodel.com

    Here's also a simple walk-through for creating a JSON based app: http://www.touch-code-magazine.com/how-to-make-a-youtube-app-using-mgbox-and-jsonmodel/

提交回复
热议问题