views:

19

answers:

2

Hello all,

I have another JSON array related question.

How would I access the data stored under "when": in this array if I am importing it with JQuery with a statement like this:

function getJSON() {
    $.getJSON('nearby.json',
    function(data) {
            console.log(data.when);
        });
 }

Here is a snippet from my JSON:

[
    [
        "Soon",
        [
            {
                "body": "",
                "updated": "2010-06-25T09:53:50.868000",
                "distance": 27.679736723643234,
                "when": "lunchtime",
                "item_types": [
                    5 
                ],
                "ccnt": 12,
                "loc": {
                    "lat": 37.774929499999999,
                    "lon": -122.4194155 
                } 
            } 
        ] 
    ] 
]
+2  A: 
data[0][1][0].when

But if you're producing that JSON, it's somewhat confusing. Do you need to have an array containing a string ("Soon") and another array?

Matthew Flaschen
Thanks! that worked. It'll let me accept your answer in a couple of minutes
fordays
Thats what my django setup is spitting out in the dump. I wish it were different! "Soon" is just the title for a bunch of arrays that will be concatenated on to this one... for example: data[0][1][0,1,2,3...n]
fordays
A: 

so some of the items in the thing would alert as:(alerted value at the end in the comment)

alert(data[0][0]);//"Soon"
alert(data[0][1][0].updated);//"2010-06-25T09:53:50.868000"
alert(data[0][1][0].when);//"lunchtime"
alert(data[0][1][0].item_types[0]);//5
alert(data[0][1][0].loc.lat);//37.774925,
Mark Schultheiss