www.webdeveloper.com
Results 1 to 3 of 3

Thread: JSON accessing "numbered" object values

Hybrid View

  1. #1
    Join Date
    May 2011
    Location
    NZ
    Posts
    2

    JSON accessing "numbered" object values

    I guess I'm really thick, but I am going crazy with this JSON object:

    Code:
    var json={
       "item":"random",
       "results":{
          "1":"test"
        }
    }
    Now,
    Code:
    alert(json.item);
    gives me "random". Great.

    But obviously
    Code:
     alert(json.results.1)
    won't work. How do I access the key/value pair in json.results?

    Cheers,
    c00ch

  2. #2
    Join Date
    May 2011
    Location
    NZ
    Posts
    2

    Doh!

    Strike my previous question. All I needed was a bit of chocolate and the question answered itself

    Code:
    alert(json.results["1"]);

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    don't need quotes:

    Code:
    alert(json.results[1]);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles