How can I check If I got null from json?

后端 未结 5 977
孤独总比滥情好
孤独总比滥情好 2020-12-31 09:13

Here I got from JSON

[{\"photo\":null}]

and I use this code

NSMutableArray *jPhoto = [NSMutableArray arrayWithArray:(NSArray *)[jsonDict va         


        
5条回答
  •  天涯浪人
    2020-12-31 09:36

    Macros can be helpful if payload is complex JSON structure having possible values.

    #define SET_IF_NOT_NULL(TARGET, VAL) if(VAL != [NSNull null]) { TARGET = VAL; }
    

    and macro can be referenced like

    SET_IF_NOT_NULL(myRecord.name, [jsonData objectForKey:@"name"]);
    

提交回复
热议问题