Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

属性和key大小写匹配的问题 #168

Closed
goodcyg opened this issue Apr 1, 2016 · 8 comments
Closed

属性和key大小写匹配的问题 #168

goodcyg opened this issue Apr 1, 2016 · 8 comments

Comments

@goodcyg
Copy link

goodcyg commented Apr 1, 2016

如果属性和json里的key,大小写不匹配的话,json转模型就是失败的。但是一个项目这种情况很多啊,改起来是个体力活。你对这个问题是咋看?啥好的解决方案?

@ibireme
Copy link
Owner

ibireme commented Apr 2, 2016

实现 modelCustomPropertyMapper 来返回自定义映射关系啊。
JSON 和 Property 都是大小写敏感的,比如 underlineunderLine 就是两个不同的属性,这不可能去忽略大小写来做映射。

@goodcyg
Copy link
Author

goodcyg commented Apr 3, 2016

明白了,原来你这里已经做了处理,非常好 呵呵。
还有一个问题+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper 是YYModel可选协议,一般我们是要在实现类中写上'',你把 写在分类中,就不需要在There's no need to add '' to your class header.?

@goodcyg
Copy link
Author

goodcyg commented Apr 3, 2016

There's no need to add '' to your class header.

这样到挺方便的,免得加一大堆的协议头,你咋样的实现原理?麻烦解释一下.谢谢。

@ibireme
Copy link
Owner

ibireme commented Apr 3, 2016

这里只会检测是否实现了具体方法,而不是去检测是否实现整个协议,所以加不加 的声明都是无所谓的。

@goodcyg
Copy link
Author

goodcyg commented Apr 3, 2016

这里只会检测是否实现了具体方法,而不是去检测是否实现整个协议,所以加不加 的声明都是无所谓的。

定义成协议,而又不是按协议方式来。有点费解.
那是否可以这样,在NSobject的分类中定义一个方法+ (nullable NSDictionary *)modelCustomPropertyMapper,让子类去重新实现它?而不用搞成 协议声明?

@ibireme
Copy link
Owner

ibireme commented Apr 3, 2016

如果你愿意按照协议来,在 model 的 interface 里面声明了 ,那这就是 "定义成协议,也按协议方式来" 了。

协议里面的方法都是可选的,我在内部做检测时,仍然还是需要针对每个方法做判断,而不能直接判断是否实现了 协议。所以,这里也允许了使用者不去写这个 \<YYModel\>

在 NSObject 上定义方法也行,但这会污染 NSObject 的函数命名空间,还会带来未实现方法的编译警告。

@goodcyg
Copy link
Author

goodcyg commented Apr 4, 2016

谢谢,你的解答,顺便问一下,你处理过app 访问的DNS被劫持的问题?有能分享一下经验?

@ibireme
Copy link
Owner

ibireme commented Apr 4, 2016

没有,不过可以试试 HttpDNS 之类的方式来直接访问 IP。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants