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

 

posted on 2019-04-15 13:14  七七2020  阅读(23314)  评论(0编辑  收藏  举报

导航