0

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 
                } 
            } 
        ] 
    ] 
]
0

2 Answers 2

2
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?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! that worked. It'll let me accept your answer in a couple of minutes
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]
0

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,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.