您好我使用改造来带回一个java对象, 我想根据响应中的一个字段更改文本字段 但我无法在网上找到如何做到这一点,
这是我的改造界面:
public interface retrofitApi {
String baseUrl = "http://192.168.137.1:3003/";
@GET("api/radBox/getDegrees")
Call<ResponseBody> getCallData();
//Call<degreesModel> getCallData();
class Factory {
private static retrofitApi service;
public static retrofitApi getInstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(retrofitApi.class);
return service;
} else {
return service;
}
}
}
}
这是我的回复:
retrofitApi.Factory.getInstance().getCallData().enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//HERE I WANT TO DO RESPONSE.BODY.SOMEHING ?
//HERE I WANT TO DO RESPONSE.BODY.SOMEHING ?
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("myLogs", "failed to Retrive Data");
Log.d("myLogs", "becouse: "+t);
largeTextVar.setText("failed: " + t);
}
});
}
我的json看起来像这样:
{
"data": {
"sector": [
[
{
"scanned": false,
"sectorOne": "",
"sectorTwo": "",
"sectorThree": ""
},
{
"scanned": false,
"sectorOne": "",
"sectorTwo": "",
"sectorThree": ""
}
]
]
},
"curserLocation": {
"elevation": 30,
"horizontal": 105
}
}
如何从响应中访问我的json中的一个字段?
THNX ALLOT !!