DataBean.java:数据实体
public class DataBean {
private String user;
private int pass;
@Override
public String toString() {
return "DataBean{" +
"user='" + user + '\'' +
", pass=" + pass +
'}';
}
public DataBean(String user, int pass) {
this.user = user;
this.pass = pass;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public int getPass() {
return pass;
}
public void setPass(int pass) {
this.pass = pass;
}
}
使用
String json = "[" +
"{\"user\":\"admin\"," +
"\"pass\":12345}," +
"{\"user\":\"admin\"," +
"\"pass\":12345}" +
"]";
List<DataBean> list = new Gson().fromJson(json,
new TypeToken<List<DataBean>>() {}.getType());
|