Json 解析中的 Retrofit 2 错误

Retrofit 2 error in Json parsing

我想在 url 上发送不带参数的 post 响应。但是我得到的回应是

[Lcom.example.c4u015.retrotestapp.Questions;@97ddd71

但实际响应是这样的

 {
"MemberDays": "[{"Dt":"02/19/2016","AM":"0","AMS":"1","NS":"0","NSS":"0","PM":"1","PMS":"0","SB":"0","DS":"0","Note":""},{"Dt":"02/25/2016","AM":"0","AMS":"0","NS":"0","NSS":"0","PM":"0","PMS":"0","SB":"0","DS":"0","Note":""}]"
"Message": ""
"Status": "0"
}

这是我的代码。

   Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.1.99:82/MembersWS.svc/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        gitAPI WhosebugAPI = retrofit.create(gitAPI.class);

        Call<Questions[]> call = WhosebugAPI.loadQuestions();

         call.enqueue(new Callback<Questions[]>() {
             @Override
             public void onResponse(Response<Questions[]> response, Retrofit retrofit) {
                 if (response.isSuccess()) {
                     Questions[] user = response.body();
                     Log.e("parsed"," on response");
                     Log.e("response", response.body().toString()+" "+response.raw().toString());
                 } else {
                     int statusCode = response.code();
Log.e("status",""+statusCode);
                     // handle request errors yourself
                     ResponseBody errorBody = response.errorBody();
                 }
                 pd.dismiss();


             }

             @Override
             public void onFailure(Throwable t) {
                 pd.dismiss();
                 Log.e("error", t.getLocalizedMessage());
                 Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
             }
         });

这是我用过的界面

public interface gitAPI {
    @POST("GetMemberAvailability/MBR0011581")
    Call<Questions[]> loadQuestions();
}

你正在打印 toString() 的输出,在这种情况下是 object id,它的值是你看到的 [Lcom.example.c4u015.retrotestapp.Questions;@97ddd71

您的响应是一个问题类型的数组,因此要打印输出,您必须遍历数组的项目并调用 getters ,例如:

user[0].getXXX(); 其中 XXX 是 class 问题的任何 getter 方法

或者您可以使用 for loop 或您希望的其他流程