首页 > 解决方案 > 响应是动态的:需要一个字符串,但在第 1 行第 149 列是 BEGIN_OBJECT

问题描述

这是我的 GSON 响应,我的响应是动态的。

注意:我无法更改响应

{   "soapBody": {
    "GenerateProposalResponse": {
      "GenerateProposalResult": {
        "POL_SYS_ID": "102123205",
        "PROPOSAL_NO": "10083\/31\/20\/P\/0004354",
        "VehicleIDV": {

        },
        "ERROR_DESC": "Proposal created successfully......!",
        "ERROR_CODE": "0",
        "CoverDtlList": {
          "CoverDtl": [
            {
              "CoverDesc": "BASIC TP COVER",
              "Premium": "752",
              "Type": {

              }
            },
            {
              "CoverDesc": "GR36A-PA FOR OWNER DRIVER",
              "Premium": "315",
              "Type": "ADD"
            },
            {
              "CoverDesc": "TP TOTAL",
              "Premium": "1067",
              "Type": {

              }
            },
            {
              "CoverDesc": "TOTAL PREMIUM",
              "Premium": "1067",
              "Type": {

              }
            },
            {
              "CoverDesc": "IGST",
              "Premium": "192",
              "Type": "ADD"
            },
            {
              "CoverDesc": "TOTAL AMOUNT",
              "Premium": "1259",
              "Type": {

              }
            }
          ]
        }
      }
    }   } }

很多时候,我得到了“VehicleIDV”:“1230”,很多时候我得到了“VehicleIDV”:{}

W/System.err:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:需要一个字符串,但在第 1 行第 149 列路径 $.soapBody.GenerateProposalResponse.GenerateProposalResult.VehicleIDV 是 BEGIN_OBJECT

这是我的功能

public void getShri(final Context mContext, String id) {
    ApiClient restClient = new ApiClient(mContext);
    restClient.setCommunication();
    ApiInterface apiService = restClient.getApiService();

    try {
        Call call = apiService.getShri(id);
        call.enqueue(new Callback<Shri>() {
            @Override
            public void onResponse(Call<Shri> call, Response<Shri> response) {
                if (response.isSuccessful()) {
                    Shri commonResponse = response.body();
                    ((onRequestCompleteCallBackListener) mContext).
                            onResponse(commonResponse);
                }
            }

            @Override
            public void onFailure(Call<Shri> call, Throwable t) {
                //onResponse(t);
                t.printStackTrace();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

这是api接口代码

 @FormUrlEncoded
    @POST("shri.php")
    Call<Shri> getShri(@Field("id") String id);

标签: androidgson

解决方案


推荐阅读