aha, found it.  the toSource() method of object does the trick.  (is there a
way in Proto that's better?)

...

> var jsonarray = transport.responseText.evalJSON(true);
> var test = jsonarray.toSource(); //returns my array of hashes
> alert(test);
>
...

Thanks once again for the sounding board ...(seems to usually work when
debugging)

cheers, all-


On 6/7/07, Mark Holton <[EMAIL PROTECTED]> wrote:
>
> Thanks.  Unfortunately, that works the same as what I was trying with "var
> jsonarray = transport.responseText.evalJSON(true);".
>
> ...I know the string passed back is:
>
> > [{"VIDID":3359,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"test22"},{"VIDID":3358,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"some
> > other descrip"}]
> >
>
> When I display the alert below, I receive the message:
>
> [object Object]
> >
>
> When I try to access an element of that array, via alert(jsonarray[1])...
> I return:
>
> > undefined
> >
>
> new Ajax.Request(url,
>             {
>                 method: 'post',
>                 parameters: pars,
>                 onComplete: function(transport)  //get from JSON string
>                   {
>                     var jsonarray = transport.responseText.evalJSON(true);
>                     alert(jsonarray);
>                     var item = jsonarray[1];
>                     alert(item);
>                   }
>             }
>         );
>
> On 6/7/07, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote:
> >
> >
> > I use this
> >
> > var obj = eval( "(" + t.responseText + ")" );
> >
> > Hope that helps;
> >
> > On Jun 8, 12:18 am, "Mark Holton" <[EMAIL PROTECTED]> wrote:
> > > Using Proto 1.5.1:
> > >
> > > Let's say my server side code returns a JSON string with is an Array
> > of
> > > hashes (with name-value pairs), such as in this case, where I return
> > an
> > > array of 3 hashes via an Ajax.Request invocation:
> > >
> > [{"VIDID":3359,"VIDPATHSTR":"/SS/vids/123","VIDDESCRIP":"test22"},{"VIDID":3358,"VIDPATHSTR":"
> > > /SS/vids/123","VIDDESCRIP":"some other descrip"}]
> > >
> > > While the following works very nicely for a single JSON object
> > returned...
> > > doesn't work directly on an array...
> > > var json = transport.responseText.evalJSON(true);
> > >
> > > In Prototype, what's the easiest way to turn that returned JSON string
> > of an
> > > array of hashes into an object that's accessible via name/value pairs
> > in my
> > > function?
> > >
> > > Many thanks for any words of wisdom!
> > > cheers,
> > > Mark
> >
> >
> > > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to