访问JSON数据 [英] Accessing JSON data

查看:78
本文介绍了访问JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果网络服务为我提供了以下数据:

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

我如何访问第二个col1?

how do I access the second col1?

如下:

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

给我:

[object Object],[object Object]

推荐答案

它是一个包含2个包含col1col2的元素的数组,所以类似:

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

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

(0是第一个元素,然后选择"col1")

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

这篇关于访问JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆