On 08/17/2009 10:03 PM, Luke wrote:
> 
> 
> Below is json object that I am having trouble with.  When I try to use
> this object with JSONParser.parse(), I get JSONException.  I have
> verified that the JSON object is of valid form but cannot figure out
> why I am getting the exception.  I have narrowed it down to the
> particular line of code that contains JSONParser.parse();
> 
> Anyone see anything here?

Well, all that JSONParser() does is to call eval() on the string. Try
wrapping the object in parenthesis:

$! Notice that the string is now quoted.
$! This simulates what that client receives.
$ head /tmp/foo.js
x ='{"projects":[{"id":"1","title":"Project Number
1","priority":"High","openDate":"2009-06-05","closeDate":"2009-06-07","owner
<snip>

Well I'm a Rhino man
Well, don't you know I am?
(apologies to F. Zappa)

$ rhino
js> load("/tmp/foo.js")
js> print(x.toSource())
(new String("{\"projects\":[{\"id\":\"1\",\"title\":\"Project Number
1\",\"priority\":\"High\",\"openDate\":\"2009-06-05\",\"closeDate\":\"2009-06-07\",\"owner\":
{\"firstName\":\"John\",\"lastName\":\"Doe\
<snip>

js> print (eval(x))
js: "<stdin>#4(eval)", line 1: uncaught JavaScript runtime exception:
SyntaxError: missing ; before statement
        at <stdin>:4
<snip>

js> print(eval('('+x+')'))
[object Object]


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to