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
提一个建议,望改进 #109
Comments
@Mosaics 你意思是,当拿到网络层返回的数据的时候,已经是JSON格式了,并不是字符串,对吧?那请问下,这个JSON格式,具体是代码中的什么类型呢? 如Foundation中提供的 |
这个我是知道的,我的建议里也是这么说的,只是不足的一点,返回一个字符串直观看起来,json的层次结构并不是那么好看,建模的时候困难,必须要自己反序列化成标准的json格式树,才知道怎么建模。所以我才想能不能你这边的库层级提供一个api通过json格式序列化。其实内部也就是你说的 将传入的json再序列化成字符串就能满足你当前的接口调用。仅仅只是对外方便些
… 在 2017年4月11日,下午4:22,xuyecan ***@***.***> 写道:
你意思是,当拿到网络层返回的数据的时候,已经是JSON格式了,并不是字符串,对吧?那请问下,这个JSON格式,具体是代码中的什么类型呢?
如Foundation中提供的JSONSerialization.jsonObject(with:options:)函数,实际上,它的返回值实际是NSArray或者NSDictionary,是可以转换成NSArray/NSDictionary然后通过HandyJSON现有的API进行反序列化的。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwi_Z54B8JeCuyHYkj8ifNo2_1YbUks5ruzg9gaJpZM4MrY4Z>.
|
@Mosaics 我还是不是特别理解。“所以我才想能不能你这边的库层级提供一个api通过json格式序列化”这句话里指的‘JSON格式’具体是什么格式?在代码里,它的类型是什么呢? |
比如 swift里 Alamofire 请求返回的 responseJSON方法的json格式
… 在 2017年4月11日,下午4:39,xuyecan ***@***.***> 写道:
@Mosaics <https://github.com/Mosaics> 我还是不是特别理解。“所以我才想能不能你这边的库层级提供一个api通过json格式序列化”这句话里指的‘JSON格式’具体是什么格式?在代码里,它的类型是什么呢?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwqpbln_1NuyaiQlgpgS6XGO86rswks5ruzwxgaJpZM4MrY4Z>.
|
其实这也不是一个必选项,建模可以按接口文档来写。但如果需要有容错检查,我还是觉得还是有必要提供这么一个api(虽然不提供也就是代码里面多几句转换)
… 在 2017年4月11日,下午4:39,xuyecan ***@***.***> 写道:
@Mosaics <https://github.com/Mosaics> 我还是不是特别理解。“所以我才想能不能你这边的库层级提供一个api通过json格式序列化”这句话里指的‘JSON格式’具体是什么格式?在代码里,它的类型是什么呢?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwqpbln_1NuyaiQlgpgS6XGO86rswks5ruzwxgaJpZM4MrY4Z>.
|
这么说吧,其实就是实现你这个功能。
… 在 2017年4月11日,下午4:39,xuyecan ***@***.***> 写道:
@Mosaics <https://github.com/Mosaics> 我还是不是特别理解。“所以我才想能不能你这边的库层级提供一个api通过json格式序列化”这句话里指的‘JSON格式’具体是什么格式?在代码里,它的类型是什么呢?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwqpbln_1NuyaiQlgpgS6XGO86rswks5ruzwxgaJpZM4MrY4Z>.
|
@Mosaics 我明白你意思了。但是,正如‘Alamofire 请求返回的 responseJSON方法的json格式’,它的 所以这就是我要说的,其实没必要先转换到String,直接做个cast就可以传入 |
是的,我也这么觉得。搞成string,就算解析数据建模照着接口文档写,万一有容错,字符串找都找不到,一点都不直观。
… 在 2017年4月11日,下午4:59,xuyecan ***@***.***> 写道:
@Mosaics <https://github.com/Mosaics> 我明白你意思了。但是,正如‘Alamofire 请求返回的 responseJSON方法的json格式’,它的responseJSON()中拿到的数据,实际正是从JSONSerialization.jsonObject(with:options:)得到的(Alamofire文档明确提到它使用NSJSONSerialization做JSON反序列化)。它是Any类型,实际使用时,需要转换到NSDictionary或者Dictionary<String, Any>,而HandyJSON是有接口直接接受这两个类型的。
所以这就是我要说的,其实没必要先转换到String,直接做个cast就可以传入HandyJSON现有的接口了。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwpfvovRjzNcyZdfuBo2bIRh39dDzks5ru0EFgaJpZM4MrY4Z>.
|
所以现在不需要修改了呀。Foundation提供的NSJSON相关的方法,在提到
|
….感觉饶了一圈,我知道这些方法,我想说的是,其实就是实现
Features
里的 From JSON 接口,虽然现在做到这个程度已经可以了 自己本身就可以支持
… 在 2017年4月11日,下午5:05,xuyecan ***@***.***> 写道:
所以现在不需要修改了呀。Foundation提供的NSJSON相关的方法,在提到JSON格式时,指的东西本质上一般是NSDictionary(虽然JSON顶层对象也允许NSArray)。现在的接口是支持的。
public static func deserialize(from dict: NSDictionary?, designatedPath: String? = nil) -> Self?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#109 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMoCwtD1AUhVnt5WC29yJPKyo1-k7jb4ks5ru0JBgaJpZM4MrY4Z>.
|
@Mosaics 但你想一下,如果要提供一个 是 这两个接口,不是都和 |
如上述,暂不考虑添加此接口。 |
大家都知道,现在网络请求的数据多数以json格式解析,json格式有个好处是在控制台打印出来后有结构性,结构层次一清二楚,虽然也可以将请求的json格式转换成json字符串,但是通过字符串转换相当的不直观,不知道能不能以json格式转换?我吃了几次亏,后台接口写的字段和实际的并不相符,我建模型的时候字段老是对不上,还在傻傻的去找错误!实际上json字符串一长串,根本就不好找。
归根结底,现在只支持jsonString -> model, 并不支持json -> model
其实我觉得提供额外方法(最偷懒的做法)也快,直接将返回的json序列化成字符串再调用现有的接口即可
The text was updated successfully, but these errors were encountered: