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();
        }

猜你喜欢

转载自www.cnblogs.com/webttt/p/10710101.html