我正在尝试获取外部Web服务的内容,该服务以JSON格式返回用户数组,然后将JSON响应转换为EclipseUser对象数组。来自Web服务的响应将用户数组包装在标记为“users”的数组中。我做了一些研究,但似乎无法找到一个示例,告诉我如何获取用户数组中的项目,然后将它们转换为对象。
{
users: [
{
id: 2,
name: "David Cook",
username: "david.cook",
password: "12345",
email: "david.cook@mydomain.com"
},
{
id: 5,
name: "Kieran Barnby",
username: "kieran.barnby",
password: "12345",
email: "kieran.barnby@mydomain.com
}
]
}
我想知道如何检索JSON然后将其转换为对象数组。这是对象类:
public class EclipseUser {
public int id;
public String name;
public String username;
public String password;
public String email;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}