Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JSON returns 'invalid label' error...please help..

    I am returning the following JSON data from a PHP Script:

    Code:
    {"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....

    Code:
    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..

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,343
    Thanks
    11
    Thanked 589 Times in 570 Posts
    there seems to be a line break in "Gary Nicholas" that's causing the problem.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple solution...

    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!

  • #4
    New Coder
    Join Date
    Nov 2008
    Location
    New Delhi,India
    Posts
    26
    Thanks
    1
    Thanked 3 Times in 3 Posts
    one more thing. DO NOT USE eval EVER. See on crockford's site http://javascript.crockford.com/code.html


    --
    Vijay
    http://vijayjoshi.org

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could u pls send me the links to learn JSON?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •