JSONModel 的常见错误

作者: 青青草原饲养源与园叮叮叮叮 | 来源:发表于2016-08-18 12:53 被阅读2278次

开始感谢JSONModel的开源,其成为了项目开发必备的开源库。
我在网络层中使用了瘦model的思想,业务层与网路层交互的全都是继承自JSONModel 的model。
在开发过程中遇到了很多错误,再此空暇之际总结,方便以后查找。

Paste_Image.png

以上图model为例。
1.[__NSCFDictionary name]: unrecognized selector sent to instance

这种情况是:NSArray<WJPerson> * data;写成了NSArray<WJPeson> * data;尖括号中为协议,不是指针。JSONModel利用协议这一特性,在解析的时候获得需要将数据转化的类型,这由JSONModel实现,不是oc的泛型。
2.
Terminating app due to uncaught exception 'Bad property protocol declaration', reason: '<XCBCarPlaceModel> is not allowed JSONModel property protocol, and not a JSONModel class.*

这种情况是没有XCBCarPlaceModel类的实现。
@implementation XCBCarPlaceModel
@end

3.** Invalid JSON data. Required JSON keys are missing from the input. Check the error user information.**

这是model里面的数组,默认是必需的,要是返回回来的model没有包含此字段就会造成解析失败。
4.toJSONString 方法,当model的属性为nil为其被Optional修饰,那么得到的此字符串就没有该属性,如果nil为requerid那么就是该属性其值为null.

相关文章

网友评论

    本文标题:JSONModel 的常见错误

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