如何用Retrofit直接获得Json数据
1个回答
展开全部
public void delAddr2(String baseUrl,HashMap<String,String> map){
addrManageModel.delAddr2(baseUrl, map).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
Logger.t(TAG).d(response.body().toString()+"===="+response.message()+"==="+response.code());
BufferedSource source = response.body().source();
try {
source.request(Long.MAX_VALUE); // Buffer the entire body.
} catch (IOException e) {
e.printStackTrace();
}
Buffer buffer = source.buffer();
Charset charset = UTF8;
MediaType contentType = response.body().contentType();
if(contentType != null){
charset = contentType.charset(UTF8);
//获取Response的body的字符串 并打印
Logger.t(TAG).d(buffer.clone().readString(charset));
addrManageView.delAddrShow(buffer.clone().readString(charset));
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
在页面上调用:
delAddrShow()更新UI即可。
addrManageModel.delAddr2(baseUrl, map).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
Logger.t(TAG).d(response.body().toString()+"===="+response.message()+"==="+response.code());
BufferedSource source = response.body().source();
try {
source.request(Long.MAX_VALUE); // Buffer the entire body.
} catch (IOException e) {
e.printStackTrace();
}
Buffer buffer = source.buffer();
Charset charset = UTF8;
MediaType contentType = response.body().contentType();
if(contentType != null){
charset = contentType.charset(UTF8);
//获取Response的body的字符串 并打印
Logger.t(TAG).d(buffer.clone().readString(charset));
addrManageView.delAddrShow(buffer.clone().readString(charset));
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
在页面上调用:
delAddrShow()更新UI即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询