Hi Quite right - if you call eval(json) where 'json' begins with a curly brace it is interpreted as the beginning of a Block rather than an ExpressionStatement (cf. section 12.4 of ECMA-262[0]).
The reason the code in the StockWatcher example works is that the JSON returned is an array, so always begins with '['. Stephen [0] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf On May 15, 5:08 am, ziglionz <[email protected]> wrote: > Hi, > > I find confusing in the tutorial (http://code.google.com/webtoolkit/ > tutorials/1.6/JSON.html), this method, as it's written: > > private final native JsArray<StockData> asArrayOfStockData(String > json) /*-{ > return eval(json); > }-*/; > > It might work with the StockWatcher example json string, I haven't > tried. > But definitely it doesn't work with any json string. > Shouldn't the call to the native eval() rather be: > > /*-{ > return eval('(' + json + ')') > }-*/; > > Until I've discovered that, I kept getting a javascript exception. > I'm new to all this, but since I've spent an aftenoon trying to > understand where the problem was, I thought what I discovered might be > helpful for others starting with JSON. > > Emanuel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" 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/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
