步骤
①、转为JsonArray格式
②、使用Iterator进行遍历准备
String relation = "[{"codeId":"1","codeName":"你们"},{"codeId":"2","codeName":"他们"}]";
JSONArray ja=JSON.parseArray(relation);
Iterator<Object> it = ja.iterator();
List<PubCodeModel> list=new ArrayList<PubCodeModel>();
while (it.hasNext()) {
JSONObject ob = (JSONObject) it.next();
PubCodeModel model = null;
if(ob.getString("codeId")!=null){
model=new PubCodeModel();
model.setVcode(ob.getString("codeId"));
}
if(ob.getString("codeName")!=null){
model.setVname(ob.getString("codeName"));
}
if(model!=null){
list.add(model);
}
}
关键CODE
Iterator<Object> it = ja.iterator();
while (it.hasNext()) {
JSONObject ob = (JSONObject) it.next();
}