View Single Post
Old 11-06-2007, 11:34 PM   #1 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Angry 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!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote