How to convert hashmap to JSON object in Java

前端 未结 29 2345
谎友^
谎友^ 2020-11-22 11:20

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

29条回答
  •  春和景丽
    2020-11-22 11:44

    I'm using Alibaba fastjson, easy and simple:

    
        com.alibaba
        fastjson
        VERSION_CODE
    
    

    and import:

    import com.alibaba.fastjson.JSON;
    

    Then:

    String text = JSON.toJSONString(obj); // serialize
    VO vo = JSON.parseObject("{...}", VO.class); //unserialize
    

    Everything is ok.

提交回复
热议问题