Ree*_*ziz 1 java arrays android json retrofit
我是RetrofitLibrary的新手,我曾经使用Volley我试图在对象内解析数组但是我不知道怎么做这里是我的Json响应
{
"response": {
"code": "1",
"success": true,
"customers": [
{
"id": 1,
"name": "reem",
"customer_type": "1",
"address": "45????",
"mobile_no": "05684412211",
"phone_no": "414511555",
"created_at": "2018-07-30 08:26:48",
"updated_at": "2018-07-30 08:26:48"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我想从响应响应中获取客户数组,这里是客户模型:
public class Customer {
@SerializedName("id")
private Integer id;
@SerializedName("customer_type")
private Integer customer_type;
@SerializedName("name")
private String name;
@SerializedName("address")
private String address;
@SerializedName("mobile_no")
private String mobile_no;
@SerializedName("phone_no")
private String phone_no;
public Customer(Integer id, Integer customer_type, String name, String address, String mobile_no, String phone_no) {
this.id = id;
this.customer_type = customer_type;
this.name = name;
this.address = address;
this.mobile_no = mobile_no;
this.phone_no = phone_no;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCustomer_type() {
return customer_type;
}
public void setCustomer_type(Integer customer_type) {
this.customer_type = customer_type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getMobile_no() {
return mobile_no;
}
public void setMobile_no(String mobile_no) {
this.mobile_no = mobile_no;
}
public String getPhone_no() {
return phone_no;
}
public void setPhone_no(String phone_no) {
this.phone_no = phone_no;
}
}
Run Code Online (Sandbox Code Playgroud)
这是数据服务接口:
@GET("get_customers")
Call<List<Customer>> getAllCustomer();
Run Code Online (Sandbox Code Playgroud)
能帮助我理解如何解析并感谢你.
创建另一个POJO类,它将具有这样的List
public class Response{
@SerializedName("response")
private Response response;
@SerializedName("code")
private String code;
@SerializedName("success")
private boolean success;
@SerializedName("customers")
private List<Customers> customers;
public void setResponse(Response response){
this.response = response;
}
public Response getResponse(){
return response;
}
public void setCode(String code){
this.code = code;
}
public String getCode(){
return code;
}
public void setSuccess(boolean success){
this.success = success;
}
public boolean isSuccess(){
return success;
}
public void setCustomers(List<Customers> customers){
this.customers = customers;
}
public List<Customers> getCustomers(){
return customers;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的数据服务接口中
@GET("get_customers")
Call<Response> getAllCustomer();
Run Code Online (Sandbox Code Playgroud)
然后,您可以在从改装电话中获取机构后获得此类客户列表
reponse.getCustomers();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1320 次 |
| 最近记录: |