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

2019-07-16  本文已影响0人  Dove_iOS

三种解决办法:

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

上一篇 下一篇

猜你喜欢

热点阅读