Why do you not want to use eval()? That's what jQuery 1.3.2 does in $.getJSON and $.ajax:
// Get the JavaScript object, if JSON is used. if ( type == "json" ) data = window["eval"]("(" + data + ")"); Or better, you can use this code from jQuery 1.3.3: // Get the JavaScript object, if JSON is used. if ( type === "json" ) { if ( typeof JSON === "object" && JSON.parse ) { data = JSON.parse( data ); } else { data = (new Function("return " + data))(); } } -Mike On Mon, Sep 7, 2009 at 11:02 PM, Alex Weber <alexwebe...@gmail.com> wrote: > > I use $.getJSON for all my ajax stuff and it works beautifully but > there is one particular situation where I use an iframe hack to do an > ajax file upload and even though the returned value is a json object > (created with PHP), jQuery treats it like a string. > > I'm using json2.js right now and it does the trick but I don't like > including that much extra code because of one rare situation. > > So my question is, be it with $.getJSON or by specifying 'json' as the > expected return type of an ajax request, jQuery *seems* to be able to > convert into json. > > The string returned is already a json object, I just need jQuery to be > able to treat it like one. I've tried wrapping it in a jQuery object > but no use. (and I really don't want to go down the eval() path)... > > Any suggestions? > > Thanks!! >