JSON to Groovy parser

后端 未结 5 2095
暗喜
暗喜 2020-12-25 13:14

I found many things about converting Groovy to JSON, but oddly enough, not the other way.

What is the (best) JSON to Groovy parser around there ?

5条回答
  •  孤城傲影
    2020-12-25 13:52

    I use JSON-lib in HTTPBuilder, but I use the JSONSlurper class to parse a string to a JSON instance:

    JSON jsonMapObject = new JsonSlurper().parse( "{integer:1, bool: true}" );
    

    To go from Object to JSON, I do this:

    //from a map:
    new JSONObject().putAll( [one:'1', two:'two']).toString()
    //from an object:
    JSONObject.fromObject( somePOGO ).toString()
    

提交回复
热议问题