How to convert hashmap to JSON object in Java

前端 未结 29 2031
谎友^
谎友^ 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:34

    this works for me :

    import groovy.json.JsonBuilder
    properties = new Properties()
    properties.put("name", "zhangsan")
    
    println new JsonBuilder(properties).toPrettyString()
    

提交回复
热议问题