使用仅包含整数或字符串的简单 json 响应进行改造
Retrofit with simple json response containing only an integer or a string
剩下的 API 我只是 returns 一个整数:12.
据我所知,这是有效的 json,但如果我能将服务器端的响应更改为更规范的内容,我会更高兴。不幸的是,这不是我的选择。
有没有一种方法也可以使用 Retrofit 来处理该响应?
编辑
参见:this question and the spec
所以新规范似乎允许使用简单的字符串或整数作为 json 文本
我找到了方法:只需使用 Integer 作为 RestCallback
:
的模板参数
new RestCallback<Integer>() {...}
剩下的 API 我只是 returns 一个整数:12.
据我所知,这是有效的 json,但如果我能将服务器端的响应更改为更规范的内容,我会更高兴。不幸的是,这不是我的选择。
有没有一种方法也可以使用 Retrofit 来处理该响应?
编辑
参见:this question and the spec
所以新规范似乎允许使用简单的字符串或整数作为 json 文本
我找到了方法:只需使用 Integer 作为 RestCallback
:
new RestCallback<Integer>() {...}