Rendering JSON in grails

后端 未结 3 520
余生分开走
余生分开走 2021-02-02 13:06

I use the following code to render data in JSON format.

render(contentType:\"text/json\") {
    results = array {
        db.eachRow(query) { row ->
                  


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 13:42

    Only off by a little bit :) Just need to change

    aMap.put("A", a)
    

    to be a collection or list, rather than a map. so something like

    def aList = []
    aList << a
    

    Will get you what you want!

    As a sidenote, there is a JSON converter in grails that will do that string building for you. Look into it here

提交回复
热议问题