SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Eval makes length undefined

    I have a json encoded array

    {"users":[{"row_id":"1","0":"Tom","1":"Cruise","2":"tomcruise","3":"1","4":"231","5":"10","6":"Old Lyme","7":"235","8":"532","9":"12"},{"row_id":"21","0":"mrs. tom","1":"cruise","2":"place","3":"0","4":null,"5":null,"6":null,"7":"6","8":"42","9":"0"}]}

    My javascript is...
    Code JavaScript:
    var search 	        = eval('(' + resp + ')');
    var search_wrap 	=[];
     
    alert(search.length);


    When my function returns the json encoded array, my alert is undefined. Is this because my array is multidimensional?

    The pre of my array is...

    Array
    (
    [users] => Array
    (
    [0] => Array
    (
    [row_id] => 1
    [0] => Tom
    [1] => Cruise
    [2] => tomcruise
    )

    [1] => Array
    (
    [row_id] => 21
    [0] => mrs tom
    [1] => cruise
    [2] => mrstomcruise
    )

    )

    )

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by unemployment View Post
    When my function returns the json encoded array, my alert is undefined. Is this because my array is multidimensional?
    Nope. It's because the search variable is an object with one property called users.

    It's that property called users which contains the array of two people.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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