我正在使用翻新2.0 Gson数据

当我检查邮递员时,我在下面得到答复

{
    "name": "Yashodhan Communication",
    "zone": "9-Belgaum",
    "tsm_name": "Tarun Patil",
    "asm_name": "Shivakumar Patil"
}


错误:


  java.lang.IllegalStateException:应该为BEGIN_ARRAY,但之前为
  第1行第2列路径$ BEGIN_OBJECT


APIClient客户端

public static Retrofit getClient() {

        retrofit = new Retrofit.Builder()
                .baseUrl("http://vehiclerescue.in/ideadarpan_beta/")
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        return retrofit;

    }


这是Pojo课

public class Appuser_Pojoclass {


    @SerializedName("name")
    @Expose
    private  String name;

    @SerializedName("zone")
    @Expose
    private  String zone;

    @SerializedName("tsm_name")
    @Expose
    private  String tsm_name;

    @SerializedName("asm_name")
    @Expose
    private  String  asm_name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getZone() {
        return zone;
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public String getTsm_name() {
        return tsm_name;
    }

    public void setTsm_name(String tsm_name) {
        this.tsm_name = tsm_name;
    }

    public String getAsm_name() {
        return asm_name;
    }

    public void setAsm_name(String asm_name) {
        this.asm_name = asm_name;
    }
}


活动课

 private void fetchAllAppUserdata()
    {

        progressBar.setVisibility(View.VISIBLE);

        Log.d("getauthkeydisplay","**** "+Idea_Urban.getInstance().get_Authkeyvalues());

        ideaInterface.get_AppUsers(Idea_Urban.getInstance().get_Authkeyvalues()).enqueue(new Callback<List<Appuser_Pojoclass>>() {
            @Override
            public void onResponse(Call<List<Appuser_Pojoclass>> call, Response<List<Appuser_Pojoclass>> response) {

                if(app_users != null)
                {
                    progressBar.setVisibility(View.INVISIBLE);
                    app_users.clear();
                }
                if(response.body()!=null) {

                    app_users.addAll(response.body());

                    Log.d("appuserresponce","*****   "+response.body());
                //    app_userDetailsAdapter.notifyDataSetChanged();
                }else
                {
                    progressBar.setVisibility(View.INVISIBLE);
                }


            }

            @Override
            public void onFailure(Call<List<Appuser_Pojoclass>> call, Throwable t) {
                Log.d("failure","**** ");

                Log.d("printmetthodsfailure","faiure"+call.toString()   + "\n "  + t.toString());

                progressBar.setVisibility(View.INVISIBLE);
            }
        });
    }


我找到一些解决方案作为谷歌的建议,但我不知道如何实现。

最佳答案

您的问题是java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

因此,您应该检查代码响应。

您的JSON响应是JSONObject,因此您应该使用Call<Appuser_Pojoclass> call

更改

Call<List<Appuser_Pojoclass>> call




Call<Appuser_Pojoclass> call

08-18 13:47
查看更多