On Tue, Jul 30, 2013 at 2:31 PM, Anthony <abasta...@gmail.com> wrote:

> So the advice is to make generic-list.json, and force that view, expecting
>> that the input is in some format we decide upon. e.g. instead of returning
>> sample_rpc_response, we return dict(result=sample_rpc_**response)?
>
>
> You could do that, but see my other response.
>
> Anthony
>
> think of it this way:

import simplejson

@request.restful()
def jsonlisttest():
    response.view = 'generic.json'

    def GET(*args, **vars):
        sample_raw_rpc_response = '["one", "two", "three"]'
        sample_rpc_response = simplejson.loads(sample_raw_rpc_response)
        result =
someOtherOperationThatCanPOTENTIALLYReturnAList(sample_rpc_response)
        return result

    def POST(*args, **vars):
        return dict()
    def PUT(*args, **vars):
        return dict()
    def DELETE(*args, **vars):
        return dict()
return locals()

The problem is that we can't be sure if the operation returns a list or a
dict, but we want to render the result as json. So, the solution where we
create a generic-list.json doesn't work for us in this case either. We
rather unavoidably end up with a list result sometimes, and if that's the
case then it just iterates over it and returns a concatenated string.

Matt

-- 
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to