无法从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;
}
答案 0 :(得分:3)
使用以下代码,您可以期望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);
}
您很高兴:)
使用返回类型Call<List<ApiResponse>>
,您“告诉”您期望的结果将是数组/列表的翻新。因此Retrofit还期望传入的json是一个数组。
因此,这将是json,翻新预期是从您的符号表示的:
[
{"error": false,
"message": "Data Found.",
"company": [...]
},
{"error": false,
"message": "Data Found.",
"company": [...]
}
...
]