Json输出List集合对象和map对象 JSON格式

Json输出List集合对象和map对象 JSON格式Json输出List集合对象 [{"属性1":["值1"],"属性2":"值2"}, {"属

Json输出List集合对象和map对象 JSON格式

Json输出List集合对象和map对象 JSON格式

//Json输出List集合对象 [{"属性1":["值1"],"属性2":"值2"}, {"属性3":["值3"],"属性4":"值4"}]

代码语言:javascript代码运行次数:0运行复制
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class PhotoVo {
    /**
     * 图片路径列表
     */
    private List<String> pathList;
    /**
     * 图片类型
     */
    private Integer type;

    public List<String> getPathList() {
        return pathList;
    }

    public void setPathList(List<String> pathList) {
        this.pathList = pathList;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    /**
     * json=[{"pathList":["/aaa.jpg"],"type":1},{"pathList":["/bbb.jpg"],"type":2}]
     * @param args
     */
    public static void main(String[] args) {
        List<PhotoVo> list = new ArrayList<PhotoVo>();
        PhotoVo vo = new PhotoVo();
        vo.setType(1);
        List<String> path = new ArrayList<String>();
        path.add("/aaa.jpg");
        vo.setPathList(path);
        list.add(vo);

        vo = new PhotoVo();
        vo.setType(2);
        path = new ArrayList<String>();
        path.add("/bbb.jpg");
        vo.setPathList(path);
        list.add(vo);

        System.out.println("json=" + JSONObject.toJSONString(list));
    }

}

//Json输出map对象 {"键1":"值1","键2":"值2"}

代码语言:javascript代码运行次数:0运行复制
/**
     * {"aaa":"bbb","111":"222"}
     * @param args
     */
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("111","222");
        map.put("aaa","bbb");
        System.out.println(JSON.toJSONString(map));
    }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2023-09-25,如有侵权请联系 cloudcommunity@tencent 删除集合jsonlistmap对象

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754976319a5223572.html

相关推荐

  • Json输出List集合对象和map对象 JSON格式

    Json输出List集合对象和map对象 JSON格式Json输出List集合对象 [{"属性1":["值1"],"属性2":"值2"}, {"属

    1月前
    210

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信