java json遍历问题,新手。 200
步骤一:导入jar
json-lib-2.2.2-jdk15.jar
json-lib依赖包:commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.jar
步骤二:建对应的实体类
public class Region(){
String category;
String cityName;
String siteName;
String total;
//省略get/set
}
步骤三:遍历
public class Test {
//将json字符串转List
public static List<Region> converListFormJson(String json){
if (json== null || json.equals("")) {
return new ArrayList();
}
JSONArray jsonArray = JSONArray.fromObject(json);
List<Region> list = (List) JSONArray.toCollection(jsonArray, Region.class);
return list;
}
public static void main(String args[]){
List<Region> list = converListFormJson();
for(Region region : list ){ //遍历所有的
System.out.println("...............业务............");
}
}
}