...

View Full Version : JSON returns 'invalid label' error...please help..



tbarbedo
01-30-2009, 07:13 PM
I am returning the following JSON data from a PHP Script:


{"box_num":"1","room_num":"305","0":{"file_num":"ABC123DF","room":"305","box":"ZGB123456","name":"Gary
Nicholas","entered_on":"01\/30\/09 11:01 AM"},"1":{"file_num":"MYFILE2","room":"305","box":"ZGB123456"
,"name":"Thiago Barbedo","entered_on":"01\/30\/09 11:01 AM"}}

I am then parsing this data in JavaScript with eval....


var objResponse = eval("(" + data + ")");

When this processes, I get an 'invalid label' error in Firebug but the results still return and I can access the data with no problems. However, I would like to remove this error from my code.

Can someone please guide me in the right direction? I have been looking for a solution for the past hour and all of the posts that correspond to this error suggest missing parens in the eval statement, however this is not the problem here....

Thanks in advance..

rnd me
01-30-2009, 08:19 PM
there seems to be a line break in "Gary Nicholas" that's causing the problem.

tbarbedo
01-30-2009, 08:52 PM
The line break is there because of the code window...the break doesn't appear in the actual data.

However, I have found my error. The reason why it was returning the 'invalid label' syntax is because in the AJAX Request the dataType parameter was defined as 'script'. This was bringing the response back as text rather than pure JSON which was causing that error.

All I have to do is remove the optional dataType parameter or change 'script' to 'json'

Thanks for trying to help though!

v08i
01-31-2009, 07:21 AM
one more thing. DO NOT USE eval EVER. See on crockford's site http://javascript.crockford.com/code.html


--
Vijay
http://vijayjoshi.org

vikasg
02-17-2009, 07:06 AM
Vijay,
I am a newbee to JSON. Could you please give me the links for learning basic JSON stuff, like from Simple examples to creating our own JSON.
Help will be really appreciated.
pls mail: vikasg18@gmail.com

-Vikas

vikasg
04-27-2009, 09:57 AM
could u pls send me the links to learn JSON?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum