[英]Check each response from retrofit 2.0
I have responses from server if good token as "users":[{"id":"1234","name":"name"}]
如果有良好的令牌,我会收到服务器的响应,例如"users":[{"id":"1234","name":"name"}]
And if bad token as "users":"logout"
如果错误的令牌作为"users":"logout"
How I may check response before convert to objects? 如何在转换为对象之前检查响应?
I want do this out onResponse method, it is possibly? 我想这样做onResponse方法,可能吗?
Assuming you're using the default Retrofit Adapter. 假设您使用的是默认的改装适配器。 When declaring your call in your Retrofit interface use Call<ResponseBody>
as the response type. 在Retrofit接口中声明呼叫时,请使用Call<ResponseBody>
作为响应类型。 When you make the call you'll get a ResponseBody
object back from which you can access the JSON by calling body()
. 进行调用时,您将获得一个ResponseBody
对象,可以通过调用body()
从中访问JSON。 You can then decide how to proceed. 然后,您可以决定如何进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.