having problems parsing JSON

P

paulfe4

i have an ajax request, where the server is returning:

{"PageDef": {
"pageName": "myname",
"queryName": "myqueryname",
"queryCtName": "myqueryctname"
}};

i have the following code handling it:

var jsontext = response.responseText;
alert( '(' + jsontext + ')' );
var jsonObj = eval( '(' + jsontext + ')' );
doSomethingWithObj( jsonObj );

the alert shows the returned content perfectly. but the eval does not
work. i'm getting "missing ) in parenthetical." for a long time i had
"not well-formed", and trying to include "var jsonObj = " in the
return, i would get "syntax error" i think. taking out the '(' an ')'
from the eval statement, i get "invalid label".

i looked around in a lot of places, but could not find anything
definitive on what *exactly* the server's JSON-formatted response
should look like.

can someone help me out?

thanks,

../paul
 
V

VK

oh - nevermind - the frackin' semicolon was killing me.

Actually you should use the default JSON parser and stringifier
<http://www.json.org/js.html> and contact the producer if something
looks like a per design fault.

I mean of course you are free to write your very own code, but it is
not acommon way (you don't write C+++ from the scratch just because you
had some problem with C++ ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top