javascriptjsonyahoo-widgets

Using JSON in a Yahoo! widget


Haaylp!

The Yahoo! Widgets spec says I can parse JSON objects using JSON.parse(). When I actually try this, and here is what I tried...

var parsed = JSON.parse('{"key": "value"}');

print (parsed);

for (p in parsed)
{
    print ("prop: "+p);
}

I get:

ReferenceError: JSON is not defined

What's going on? Is further magic required?


Solution

  • Turns out that 'JSON' is not available until after the onLoad call completes. As far as I can surmise, this is an issue only on PCs and not Macs.

    To use JSON, it does simply work out of the box, but to try it out you need to do it from a timer callback or something.