Android 通过改造获取API时出错,但相同的API正在与postman一起使用
这是我们面临的错误 com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:应为字符串,但在第1行第1119列path$.data[4]处为BEGIN对象。上次收到的\u消息Android 通过改造获取API时出错,但相同的API正在与postman一起使用,android,Android,这是我们面临的错误 com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:应为字符串,但在第1行第1119列path$.data[4]处为BEGIN对象。上次收到的\u消息 public void DeviceList(String api, final ApiType apiTypes, String page_no, String authtoken) { ProgressDialog prog
public void DeviceList(String api, final ApiType apiTypes, String page_no, String authtoken) {
ProgressDialog progressDialog = new ProgressDialog();
try {
this.pdLoading = progressDialog.getInstance(this.context);
this.pdLoading.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
if (this.pdLoading.isShowing()) {
this.pdLoading.cancel();
}
this.pdLoading.show();
} catch (Exception e) {
e.printStackTrace();
}
this.apiTypeVariable = apiTypes;
/*RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(api) //Setting the Root URL
.build();*/
Retrofit retrofit = new Retrofit.Builder().baseUrl(api).addConverterFactory(GsonConverterFactory.create()).client(okHttpClient).build();
GitApi gi = retrofit.create(GitApi.class);
call = (Call<T>) gi.getDevices(authtoken, page_no);
call.enqueue(new Callback<T>() {
@Override
public void onResponse(Call<T> call, Response<T> response) {
t = (T) response.body();
if (pdLoading.isShowing())
pdLoading.cancel();
onResponseListner.onResponse(t, apiTypeVariable, true);
}
@Override
public void onFailure(Call<T> call, Throwable t) {
Log.e(apiTypes.toString(), t.getMessage() + ".");
if (pdLoading.isShowing())
pdLoading.cancel();
onResponseListner.onResponse(null, apiTypeVariable, false);
}
});
}```
public void DeviceList(字符串api、最终ApiType apiTypes、字符串页号、字符串authtoken){
ProgressDialog=新建ProgressDialog();
试一试{
this.pdload=progressDialog.getInstance(this.context);
this.pdLoading.setProgressStyle(android.R.style.Widget\u ProgressBar\u Small);
if(this.pdLoading.isShowing()){
这是.pdLoading.cancel();
}
这个.pdLoading.show();
}捕获(例外e){
e、 printStackTrace();
}
this.apitype变量=apiTypes;
/*RestAdapter adapter=new RestAdapter.Builder()
.setEndpoint(api)//设置根URL
.build()*/
改装改装=新建改装.Builder().baseUrl(api).addConverterFactory(GsonConverterFactory.create()).client(okHttpClient.build();
GitApi gi=reformation.create(GitApi.class);
call=(call)gi.getDevices(authtoken,页码);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
t=(t)response.body();
if(pdLoading.isShowing())
pdLoading.cancel();
onResponseListner.onResponse(t,apityVariable,true);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.e(apiTypes.toString(),t.getMessage()+”);
if(pdLoading.isShowing())
pdLoading.cancel();
onResponseListner.onResponse(null,apityVariable,false);
}
});
}```
它表明将json字符串转换为模型时出现问题。具体来说,模型的一个属性被声明为字符串类型,但json字符串中有一个字段(键)映射到对象类型。请检查您的模型是否兼容以及您从api收到的结果