Hello mate
I'm trying to parse the JSON object inside the callback method from my
client side, I got a message saying "No JSON object could be
decoded"... Do you please have any idea about what I'm doing wrong in
my callback method...Below you can see the sample of the callback
method, and format of JSON message... thanks

 # from the client side I return a JSON that i want to parse:
function Save() {
  var data = $.toJSON( ....# I convert JSON object to simple text
here....));
                        $.ajax({
                                type: 'POST',
                                url: '{{=URL(r=request,f='action')}}',
                                contentType: "application/json;
charset=utf-8",
                                data: data,
                                dataType: 'json'
                                success:  function(data){ {{
 
import gluon.contrib.simplejson as sj
 
data = sj.loads(response.body.read())
                                                                    value = 
data["Name"][0]["key1"]
                                                                   }}
alert({{=value}}); }

                              });
                });

                }

Here is the format of the JSON that is sent as a response from my
action client (I can see it from Firebug debuger)

{
  "Name":
    [
     {  "Key1": "value1",
        "key2": value2,
        "data": {"key": "value3"}
     },
     {  "Key1": "value1",
        "key2": value2,
        "data": {"key": "value3"}
     },
   ]

}

Any ideas ?

Yannick P.

Do you know the
On Mar 29, 11:45 am, mdipierro <[email protected]> wrote:
> I think in the action you should do
>
> import gluon.contrib.simplejson as sj
> data=sj.loads(request.body.read())
> # then data["Name"][0]["Key1"]=="value1"
>
> On Mar 29, 10:00 am, Yannick <[email protected]> wrote:
>
> > Thanks a lot for the note and helps I appreciate it... I added the
> > callback on my ajax function... But I still have problem retrieving
> > JSON data...Here is the sample example of the JSON converted to string
> > that i pass to the Action class:
> > {
> >   "Name":
> >     [
> >      {  "Key1": "value1",
> >         "key2": value2,
> >         "data": {"key": "value3"}
> >      },
> >      {  "Key1": "value1",
> >         "key2": value2,
> >         "data": {"key": "value3"}
> >      },
> >    ]
>
> > }
>
> > I can't retrieve the value using "request.vars.Name" in my action.
> > The value of this variable is NONE i don't understand why... I'm
> > probably doing something wrong here, do you please have any idea ?
>
> > Thanks for your attention,
> > Yannick P.
>
> > On Mar 29, 10:05 am, mdipierro <[email protected]> wrote:
>
> > > Is it the same. URL is smart enough
>
> > > On Mar 28, 5:02 pm, Fran <[email protected]> wrote:
>
> > > > On Mar 28, 9:38 pm, Yannick <[email protected]> wrote:
>
> > > > > URL(r=request,c='static/js',f='jquery-1.3.2.js')
>
> > > > Should this not be:
> > > > URL(r=request,c='static',f='js',args=['jquery-1.3.2.js'])
>
> > > > F
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to