java中List转换成Json
List转换成json串
public String getNameListByID(Long Id) { List<Name> nameLists= nameService.selectNameById(Id);//获取List if(null == nameLists){ return null; } JSONArray jsonArray = new JSONArray(); for(Name nameList : nameLists){ JSONObject jo = new JSONObject(); jo.put("NameCode", nameList.getNameCode()); jo.put("Name", nameList.getName()); jsonArray.add(jo); } return jsonArray.toString(); }