tags:

views:

42

answers:

3

Hi,

How do I access the returned JSON Data? e.g the name array? to work

JSON...

{"COLUMNS":["NAME"],"DATA":[["Item 1"],["Item 2"]]} 

The data.NAME[1] doesn't seem to have any data in it..

 $.getJSON('url/json.php',
     function(data){
    $('#debug').html('data:' + data.NAME[1]);
            });
        });
+1  A: 

Not sure what you're trying to access.
data.COLUMNS[0] should get you "NAME".
data.DATA[0] should get you the ["Item 1"] array.

deceze
A: 

If you are using aspx make sure that you check data.d not data. (this was a recent change?)

Iain
its from coldfusion actually, SeralizeJSON function...oddness
Brett
+2  A: 

Parsing your JSON string

{"COLUMNS":["NAME"],"DATA":[["Item 1"],["Item 2"]]} 

will return a javascript object like:

var data = {
    COLUMNS: ["NAME"],
    DATA: [["Item 1"], ["Item 2"]]   
}

so there is no identifier for data.NAME[1].

You may access data.COLUMNS[0] returning "NAME" or data.DATA[0][0] returning "Item 1".

jAndy
+1 nice answer. You probably meant `data.DATA[0][0]` there. Weird JSON structure.
Anurag
@Anurag: doh right, missed that.
jAndy
Thanks guys, data.DATA[0][0] worked :)
Brett