| Wildhoney |
11-06-2007 11:34 PM |
JSON invalid label
I feel it's important to reiterate a point I made in this article about JSON with PHP and Javascript. The Javascript error "invalid label" may be a tough one to overcome if you're blissfully unaware of why the error's being thrown.
JSON strings look something like the following:
Quote:
{"Juicy":"Grapes","Colourful":"Dragon Fruit"}
|
However, when feeding them in to eval, you must place parenthesis around them, so your JSON line looks like so:
PHP Code:
var szJson = '({"Juicy":"Grapes","Colourful":"Dragon Fruit"})';
In an AJAX function this would look like so:
PHP Code:
var szJson = eval('(' + pResponse.responseText + ')');
After that your JSON string will be more than ready to be run through Javascript's eval without any complaints!
|