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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    115
    Thanks
    8
    Thanked 7 Times in 7 Posts

    Question Initializing js object from JSON

    An html div control (id="temp") contains the following JSON stream (and nothing else):

    {
    'Steven':
    {
    'desc':'176cm,175lbs,9/8/1978',
    'loc':'50 Any Street,Brooklyn,NY',
    'kids':'Seth,Stuart,Samuel'
    },
    'Benjamin':
    {
    'desc':'170cm,180lbs,8/14/1983',
    'loc':'123 Flora Vista, Kansas City, MO',
    'kids':'Bryan,Bobby,Bella'
    },
    'Daren':
    {
    'desc':'180cm,190lbs,12/21/1984',
    'loc':'12489 Lincoln Street, Los Angeles, CA',
    'kids':'Dominic,Dorothy,David'
    }
    }


    The js object is not initializing:

    var peeps = eval( '(' + $('#temp').text() + ')' );
    alert("peeps.Steven.desc = " + peeps.Steven.desc);


    The alert's exception message is SCRIPT5007: Unable to get value of the property 'desc': object is null or undefined

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    115
    Thanks
    8
    Thanked 7 Times in 7 Posts

    Thumbs up

    resolved.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,097
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by sbhmf View Post
    resolved.
    What was your change or fix for this problem?
    Might be useful for other forum members who come across the same problem.


  •  

    Posting Permissions

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