Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

jquery - Accessing JSON data

If I am given the following data by a web-service:

{
    "d": [
        {
            "col1": "col 1 data 1",
            "col2": "col 2 data 1"
        },
        {
            "col1": "col 1 data 2",
            "col2": "col 1 data 2"
        }
    ]
}

how do I access the second col1?

As the following:

success: function( data ) {
         alert( data.d ) ;
},

gives me:

[object Object],[object Object]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Its an array with 2 elements containing col1 and col2, so something like:

alert(data.d[1].col1);

(0 is the first element, and then you choose "col1")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...