TouchJSON, dealing with NSNull

前端 未结 3 1525
清酒与你
清酒与你 2020-11-29 06:50

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 auth

3条回答
  •  孤街浪徒
    2020-11-29 07:29

    There are libraries which deal with it. One of them is SwiftyJSON in Swift, another one is NSTEasyJSON in Objective-C. With this library (NSTEasyJSON) it will be easy to deal with such problems. In your case you can just check values you need:

    NSTEasyJSON *JSON = [NSTEasyJSON withData:JSONData];
    NSString *someValue = JSON[someKey].string;
    

    This value will be NSString or nil and you should not check it for NSNull, NULL yourself.

提交回复
热议问题