jQuery doesn't include JSON parsing separate from the getJSON, and if
you look at the source it's only a couple lines, and designed to work
with callbacks.  It does not do hardcore JSON sanitizing so you do
still need a safe source as always.

For one JSON parsing method, see http://mg.to/topics/programming/javascript/json
, one of the precursors to jQuery's support, I believe.

Also you can check jQuery's source around line 2200 for an interesting
method that does not use eval:
// Handle JSONP-style loading
window[ jsonp ] = function(tmp){
    data = tmp;
    success();
    complete();
    // Garbage collect
    window[ jsonp ] = undefined;
    try{ delete window[ jsonp ]; } catch(e){}
};

The code to 'decode' JSON is short, and eval can be very fast if you
have a safe source.  Otherwise there are utilities such as found on
www.JSON.org.

HTH

Charles

On Feb 13, 2:15 pm, J Moore <[EMAIL PROTECTED]> wrote:
> This isn't specific to jQuery. One way...
>
> var x = '{a:123,b:456}'; // json
> eval('var z='+x);
>
> z is now an object. z.a = 123, etc.
>
> -j
>
> On Feb 13, 3:47 pm, wolf <[EMAIL PROTECTED]> wrote:
>
> > hi,
>
> > what is the correct way in jQuery to decode = deserialize a JSON
> > string? jQuery itself can obviously do it as it can formulate and read
> > JSON via Ajax. But i seemingly can't find a callable in jQuery that
> > allows me to decode JSON without issuing an HTTP request. That is
> > strange to me.
>
> > Can you help?
>
> > _wolf

Reply via email to