views:

377

answers:

2

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?

A: 

Have you set the widget to use 4.5 features? JSON object was introduced in 4.5, it's not available in the older versions of Y!WE.

<?xml version="1.0" encoding="UTF-8"?>
<widget>
    <version>1.0</version>
    <minimumVersion>4.5</minimumVersion>
    <settings>
        <setting name="debug" value="on"/>
    </settings>
</widget>
Pawel Krakowiak
A: 

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.

izb
You should probably mark your own answer as accepted...
Nicolás
Thanks for that.
izb