美文网首页
iOS 数据json里的null (null) 值处

iOS 数据json里的null (null) 值处

作者: Dove_iOS | 来源:发表于2019-07-16 17:34 被阅读0次

三种解决办法:

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) 值处

      本文链接:https://www.haomeiwen.com/subject/rbgtlctx.html