2011-12-15 62 views
0

有什麼辦法來此:Grails的休息渲染並返回

def getChannelListJSON = { 
     def results = Channel2.list() 
     def t1 = System.currentTimeMillis() 

       render(contentType:"text/json") { 
         canais = array { 
           for(b in results) { 
            canal = { 

             id= b.id           
             nome= b.channel_name 
             sigla= b.channel_sigla 
            } 

           } 
         } 
       } 

     def t2 = System.currentTimeMillis() 
     def tt = t2 - t1 

       new Statistic(servico: Servicos.findByName('getChannelListJSON'), totalTime: tt, date: new Date()).save() 

    } 

,但使用的渲染,我需要使用:

return object as XML 

,因爲我需要把兼容這種休息方法與http://code.google.com/p/grails-jaxrs/wiki/GettingStarted,我不能使用渲染。

回答

0

嘗試:

JSONWithPadding getChannelListJSON(@DefaultValue("callback") @QueryParam("callback") String callback) { 
    GenericEntity genericEntity = new GenericEntity<Type>(var contains result, Type.class); 
    return new JSONWithPadding(genericEntity, callback); 
}