我正在改造,但我堅持一件事:我如何獲得響應正文的原始JSON。如何獲得一個原始的Retrofit響應字符串?
public interface ViewMenuItems {
@GET
Call<ResponseBody> listRepos(@Url String url);
}
ViewMenuItems viewMenuItems = ApiClient.getClient().create(ViewMenuItems.class);
Call<ResponseBody> responseBodyCall = viewMenuItems.listRepos(Webservices.MERCHANT + merchantId + Webservices.MENU_ITEMS_LASTMODIFIED);
responseBodyCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.d("MenuItems", "Response :: " + response.body().toString());
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("MenuItems", "Exception :: " + t.toString());
}
});
但在「的MenuItems」日誌,我沒有得到JSON響應,它的未來是這樣的
MenuItems: Response :: [email protected]
敬請通過我的職位,並建議我一些解決方案。
您曾經試圖調用'體()。字符串()',而不是'體()。的toString()'? – Salem
可能重複的[不能得到OkHttp的response.body.toString()返回一個字符串](http://stackoverflow.com/questions/28300359/cant-get-okhttps-response-body-tostring-to-return -a-string) –