当前位置: 首页 > 知识库问答 >
问题:

改装:应为BEGIN\u数组,但在第1行第2列路径处为BEGIN\u对象

应瀚
2023-03-14

从Android改型读取JSON字符串时出现问题。

{
    "error": false,
    "message": "Data Found.",
    "company": [
        {
            "SUPP_ID": "4",
            "SUPP_CODE": "CO_000004",
            "CO_ID": "1",
            "CO_NAME": "Carrots",
            "SUPP_NAME": "Chalakudy Suppliers",
            "SUPP_SHORT_NAME": "CS",
            "SUPP_MOBILE_1": "987654321",
            "SUPP_MOBILE_2": "+1 ",
            "SUPP_PHONE_1": "(456) 123-4561",
            "SUPP_PHONE_2": "",
            "SUPP_EMAIL": "chalakudi@gmail.com",
            "SUPP_ADDR_1": "Chalakudi",
            "SUPP_ADDR_2": "",
            "SUPP_ADDR_3": "",
            "SUPP_ADDR_4": "",
            "SUPP_ADDR_5": "",
            "SUPP_CITY_ID": "1864",
            "SUPP_CITY_NAME": "Chalakudi",
            "SUPP_STATE_ID": "19",
            "SUPP_STATE_NAME": "Kerala",
            "SUPP_COUNTRY_ID": "101",
            "SUPP_COUNTYR_NAME": "India",
            "SUPP_DF_PT_ID": "2",
            "SUPP_PT_CODE": "Debit",
            "SUPP_CR_UID": "1",
            "SUPP_CR_DT": "2019-05-06 15:40:07",
            "SUPP_UP_UID": "1",
            "SUPP_UP_DT": "2019-05-06 15:41:41",
            "SUPP_FRZ_YN": "0",
            "SUPP_IS_DELETED": "0"
        },
        {
            "SUPP_ID": "3",
            "SUPP_CODE": "CO_000003",
            "CO_ID": "1",
            "CO_NAME": "Carrots",
            "SUPP_NAME": "Aluva Suppliers",
            "SUPP_SHORT_NAME": "Aluva",
            "SUPP_MOBILE_1": "+91 9876543210",
            "SUPP_MOBILE_2": "+919876543210",
            "SUPP_PHONE_1": "(456) 123-123_",
            "SUPP_PHONE_2": "",
            "SUPP_EMAIL": "aluva@gmail.com",
            "SUPP_ADDR_1": "aluva",
            "SUPP_ADDR_2": "",
            "SUPP_ADDR_3": "",
            "SUPP_ADDR_4": "",
            "SUPP_ADDR_5": "",
            "SUPP_CITY_ID": "1849",
            "SUPP_CITY_NAME": "Aluva",
            "SUPP_STATE_ID": "19",
            "SUPP_STATE_NAME": "Kerala",
            "SUPP_COUNTRY_ID": "101",
            "SUPP_COUNTYR_NAME": "India",
            "SUPP_DF_PT_ID": "1",
            "SUPP_PT_CODE": "Credit",
            "SUPP_CR_UID": "1",
            "SUPP_CR_DT": "2019-05-06 15:37:39",
            "SUPP_UP_UID": "1",
            "SUPP_UP_DT": "2019-05-06 15:38:00",
            "SUPP_FRZ_YN": "0",
            "SUPP_IS_DELETED": "0"
        },
        {
            "SUPP_ID": "2",
            "SUPP_CODE": "CO_000002",
            "CO_ID": "1",
            "CO_NAME": "Carrots",
            "SUPP_NAME": "Angamaly Suppliers",
            "SUPP_SHORT_NAME": "AS",
            "SUPP_MOBILE_1": "+91 6543216540",
            "SUPP_MOBILE_2": "+1 ",
            "SUPP_PHONE_1": "(456) 123-4560",
            "SUPP_PHONE_2": "",
            "SUPP_EMAIL": "as@gmail.com",
            "SUPP_ADDR_1": "6, Aluva Main Road\r\nAngamaly",
            "SUPP_ADDR_2": "",
            "SUPP_ADDR_3": "",
            "SUPP_ADDR_4": "",
            "SUPP_ADDR_5": "",
            "SUPP_CITY_ID": "1851",
            "SUPP_CITY_NAME": "Angamaly",
            "SUPP_STATE_ID": "19",
            "SUPP_STATE_NAME": "Kerala",
            "SUPP_COUNTRY_ID": "101",
            "SUPP_COUNTYR_NAME": "India",
            "SUPP_DF_PT_ID": "1",
            "SUPP_PT_CODE": "Credit",
            "SUPP_CR_UID": "1",
            "SUPP_CR_DT": "2019-05-02 10:55:46",
            "SUPP_UP_UID": "1",
            "SUPP_UP_DT": "2019-05-06 15:38:17",
            "SUPP_FRZ_YN": "0",
            "SUPP_IS_DELETED": "0"
        },
        {
            "SUPP_ID": "1",
            "SUPP_CODE": "CO_000001",
            "CO_ID": "1",
            "CO_NAME": "Carrots",
            "SUPP_NAME": "Koratty Suppliers",
            "SUPP_SHORT_NAME": "KS",
            "SUPP_MOBILE_1": "+91 9876543210",
            "SUPP_MOBILE_2": "+1 ",
            "SUPP_PHONE_1": "(987) 654-3210",
            "SUPP_PHONE_2": "",
            "SUPP_EMAIL": "koratty@gmail.com",
            "SUPP_ADDR_1": "4/2, Ernakulam High way,\r\nKoratty",
            "SUPP_ADDR_2": "",
            "SUPP_ADDR_3": "",
            "SUPP_ADDR_4": "",
            "SUPP_ADDR_5": "",
            "SUPP_CITY_ID": "1940",
            "SUPP_CITY_NAME": "Koratty",
            "SUPP_STATE_ID": "19",
            "SUPP_STATE_NAME": "Kerala",
            "SUPP_COUNTRY_ID": "101",
            "SUPP_COUNTYR_NAME": "India",
            "SUPP_DF_PT_ID": "1",
            "SUPP_PT_CODE": "Credit",
            "SUPP_CR_UID": "1",
            "SUPP_CR_DT": "2019-05-02 10:41:16",
            "SUPP_UP_UID": "1",
            "SUPP_UP_DT": "2019-05-02 10:43:35",
            "SUPP_FRZ_YN": "0",
            "SUPP_IS_DELETED": "0"
        }
    ]
}
public class ApiResponse {

    public boolean error;
    public String message;

    @SerializedName("company")
    public List<Company> companyList;

}

class Company {

    @SerializedName("SUPP_ID")
    public int suppId;

    @SerializedName("SUPP_CODE")
    public String suppCode;

    @SerializedName("CO_ID")
    public String coID;

    @SerializedName("CO_NAME")
    public String coName;

    @SerializedName("SUPP_NAME")
    public String suppName;

    @SerializedName("SUPP_SHORT_NAME")
    public String suppShName;

    @SerializedName("SUPP_MOBILE_1")
    public String suppMobile1;

    @SerializedName("SUPP_MOBILE_2")
    public String suppMobile2;

    @SerializedName("SUPP_PHONE_1")
    public String suppPhone1;

    @SerializedName("SUPP_PHONE_2")
    public String getSuppPhone2;

    @SerializedName("SUPP_EMAIL")
    public String suppEmail;

    @SerializedName("SUPP_ADDR_1")
    public String suppAddr1;

    @SerializedName("SUPP_ADDR_2")
    public String getSuppAddr2;

    @SerializedName("SUPP_ADDR_3")
    public String suppAddr3;

    @SerializedName("SUPP_ADDR_4")
    public String suppAddr4;

    @SerializedName("SUPP_ADDR_5")
    public String suppAddr5;

    @SerializedName("SUPP_CITY_ID")
    public String suppCityId;

    @SerializedName("SUPP_CITY_NAME")
    public String suppCityName;

    @SerializedName("SUPP_STATE_ID")
    public String suppStateId;

    @SerializedName("SUPP_STATE_NAME")
    public String suppStateName;

    @SerializedName("SUPP_COUNTRY_ID")
    public String suppCountryId;

    @SerializedName("SUPP_COUNTYR_NAME")
    public String suppCountryName;

    @SerializedName("SUPP_DF_PT_ID")
    public int suppDfPtId;

    @SerializedName("SUPP_PT_CODE")
    public String suppPtCode;

    @SerializedName("SUPP_CR_UID")
    public int suppCrUid;

    @SerializedName("SUPP_CR_DT")
    public String suppCrDt;
    //"2019-05-06 15:40:07"

    @SerializedName("SUPP_UP_UID")
    public int suppUpUid;

    @SerializedName("SUPP_UP_DT")
    public String suppUpDt;

    @SerializedName("SUPP_FRZ_YN")
    public int suppFrzYn;

    @SerializedName("SUPP_IS_DELETED")
    public int suppIsDeleted;

}

共有1个答案

颛孙霖
2023-03-14

使用以下代码,您期望从json中获得其他东西,然后您实际上得到了。

public interface ApiInterface { 
   @FormUrlEncoded @POST("index.php") 
   Call<List<ApiResponse>> getSupplier(@Field("action") String action);
 }

将其更改为:

public interface ApiInterface { 
   @FormUrlEncoded @POST("index.php")
   Call<ApiResponse> getSupplier(@Field("action") String action);
 }

你可以走了:)

使用返回类型调用

所以这就是json,改型期望从您的符号中得到:

[
  {"error": false,
    "message": "Data Found.",
    "company": [...]
  },
  {"error": false,
    "message": "Data Found.",
    "company": [...]
  }
  ...
]
 类似资料: