iOS 数据json里的null (null) 值处理,NullSafe源码阅读连接

三种解决办法:

1.写个工具类,判断处理每个字段是不是[NSNull null]对象;
2.AFNetworking网络请求,设置removesKeysWithNullValues以下变量为YES:

// AFURLResponseSerialization.h
/**
Whether to remove keys with `NSNull` values from response JSON. 
Defaults to `NO`.
 */
@property (nonatomic, assign) BOOL removesKeysWithNullValues;

网络请求中:

 AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
 AFJSONResponseSerializer *response = [AFJSONResponseSerializer serializer];
 response.removesKeysWithNullValues = YES;
 manager.responseSerializer = response;

3.使用大神nicklockwood写的 NullSafe:
https://github.com/nicklockwood/NullSafe

参考:
DonnyDN的
https://blog.csdn.net/DonnyDN/article/details/78226050

你可能感兴趣的:(iOS 数据json里的null (null) 值处理,NullSafe源码阅读连接)