2011-12-15 65 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); 
}