json数据格式如下
新建一个javabean 记得加toString
public class ExpressVo {
private String com;
private String no;
/**
* @return the com
*/
public String getCom() {
return com;
}
/**
* @param com the com to set
*/
public void setCom(String com) {
this.com = com;
}
/**
* @return the no
*/
public String getNo() {
return no;
}
/**
* @param no the no to set
*/
public void setNo(String no) {
this.no = no;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "ExpressVo [com=" + com + ", no=" + no + "]";
}
}
使用谷歌的json
String result = ExpressUtil.queryExpList(); //result为json数据
JsonParser parser = new JsonParser();
JsonObject object = (JsonObject) parser.parse(result);
JsonArray array = object.get("result").getAsJsonArray();
List<ExpressVo> list = new ArrayList<ExpressVo>();
for(int i=0;i<array.size();i++){
ExpressVo express = new ExpressVo();
JsonObject sub = array.get(i).getAsJsonObject();
express.setCom(sub.get("com").getAsString());
express.setNo(sub.get("no").getAsString());
list.add(express);
}
return list;
这样就可以使用jsp的<c:foreach>标签正常的遍历需要的数据