Grails JSON array

后端 未结 4 2287
遇见更好的自我
遇见更好的自我 2021-02-08 03:18

I\'m converting a list of Foo objects to a JSON string. I need to parse the JSON string back into a list of Foos. However in the following example, parsing gives me a list of JS

4条回答
  •  眼角桃花
    2021-02-08 03:42

    If you are doing this in a Grails controller, and Foo IS indeed a domain object, don't forget that armed with your JSON map, you can also do:

    List list = [new Foo("first"), new Foo("second")]
    def jsonString = (list as JSON).toString()
    
    List parsedList = JSON.parse(jsonString) as List
    Foo foo = new Foo()
    bindData(foo, parsedList[0]);
    

提交回复
热议问题