如何在Android中使用JSON
发布retrofit2
数组?
这里我附上数据格式
{
"lat": 11.024,
"lon": 75.054,
"maxdistance": 5000,
"amintyArray": [
"5ad251cfe601aa22a8f48d98",
"5ad251dae601aa22a8f48d99",
"5ad251ece601aa22a8f48d9a"
],
"starArray": [
"5ad252b1e601aa22a8f48db1"
]
}
答案 0 :(得分:0)
在下面创建请求pojo类,它定义数组或单个值..
public class JsonData {
@SerializedName("createdAt")
private long createdAt;
@SerializedName("firstName")
private String firstName;
@SerializedName("password")
private String password;
@SerializedName("users")
private List<User> users;
public long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
之后make api for request ..
@POST("linke")
Call<Response> passJsonData(@Body JsonData jsonData);
将数据插入Json数据对象后,只传递json数据。
答案 1 :(得分:0)
pojo类喜欢打击..
public class Example {
@SerializedName("lat")
@Expose
private Double lat;
@SerializedName("lon")
@Expose
private Double lon;
@SerializedName("maxdistance")
@Expose
private Integer maxdistance;
@SerializedName("amintyArray")
@Expose
private List<String> amintyArray = null;
@SerializedName("starArray")
@Expose
private List<String> starArray = null;
public Double getLat() {
return lat;
}
public void setLat(Double lat) {
this.lat = lat;
}
public Double getLon() {
return lon;
}
public void setLon(Double lon) {
this.lon = lon;
}
public Integer getMaxdistance() {
return maxdistance;
}
public void setMaxdistance(Integer maxdistance) {
this.maxdistance = maxdistance;
}
public List<String> getAmintyArray() {
return amintyArray;
}
public void setAmintyArray(List<String> amintyArray) {
this.amintyArray = amintyArray;
}
public List<String> getStarArray() {
return starArray;
}
public void setStarArray(List<String> starArray) {
this.starArray = starArray;
}
}