java - 期望 BEGIN_ARRAY 但在改造 2 中是 BEGIN_OBJECT?

标签 java android json web-services

<分区>

我正在为一个项目使用改造 2,但我无法解析 json 的响应。

Retrofit retrofit = new  Retrofit.Builder().baseUrl("BASE_URL").addConverterFactory(GsonConverterFactory    .create()).build();
final RetrofitApi request = retrofit.create(RetrofitApi.class);
LoginModel loginModel = new LoginModel("user@mail.com",bijoy@123#");
Call<List<LoginResponse>> listCall = request.Loginner(loginModel);
listCall.enqueue(new Callback<List<LoginResponse>>() {
       @Override
       public void onResponse(Call<List<LoginResponse>> call, Response<List<LoginResponse>> response) {
             List<LoginResponse> loginModelList = new ArrayList<>();
             loginModelList = response.body();  

json 响应是这样的

 {
      "response": {
        "errorCode": "",
        "errorMsg": "",
        "successCode": "SUB001",
        "successMsg": "Login successfully",
        "data": {
          "user_details": {
            "salutation": "Mr.",
            "first_name": "User",
            "last_name": "R",
            "email": "user@mail.com",
            "alternative_email": "",
            "mobile_number": "54312",
            "phone_number": "",
            "title_position": "",
            "department": "",
            "city": "",
            "street": "",
            "state": "",
            "postcode": "",
            "display_name": "Bijoy R",
            "assistant_details": "",
            "country_name": "India",
            "institution_name": "KLO",
            "user_type": "commercial"
          },
          "payment_details": [
            {
              "dateandtime": "28-07-2016 17:4736",
              "payment_mode": "DD",
              "items": "Accompanying Person",
              "transactionId": "",
              "amount": "3000.00",
              "status": "Failed"   }        ],
        }
      }
    } 

如何为这种类型的 json 编写 getter 和 setter。

最佳答案

尝试替换Call<List<LoginResponse>>Call<LoginResponse>Response<List<LoginResponse>>Response<LoginResponse>

关于java - 期望 BEGIN_ARRAY 但在改造 2 中是 BEGIN_OBJECT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38966412/

相关文章:

java - BCP 以代码 0 退出

java - Spring ClassPathXmlApplicationContext 中的 https url

android - 不断获取...DeviceMonitor] 启动监控失败

ios - 仅映射一对多关系的元素

json - 检查值是否为 typeof struct

C# 如何使用 HttpWebRequest 获取 JSON 字符串

java - SharedPreferences 中的 remove() 或 clear() 不起作用

java - "status":400, "error": "Bad Request", "message": "Required Date parameter ' 结束 ' is not present"

android - 如何在android中创建s曲线布局

android - Kotlin - 类型不匹配 : required: Context found: Context?