我在这里有一些代码json。
[
{
"id": "Node-1",
"label": "Node-1",
"image": "img/hosts.png",
"shape": "image",
"description": "Node-1:type: OS::Nova::Serverproperties: image: {get_param:image} flavor: {get_param:flavor}"
},
{
"id": "Switch-1",
"label": "Switch-1",
"image": "img/switch.png",
"shape": "image",
"description": "Switch-1:type: OS::Neutron::Netproperties: name:Switch-1Switch-1_subnet:"
}
]
我怎样才能得到"描述"使用javascript值?
答案 0 :(得分:0)
它是一个JSON对象数组,因此您可以访问array objects using index
。Read more on JavaScript Array
对于Object属性,您可以使用property属性,也可以使用Object.keys or Object.getOwnPropertyNames()
var x=[
{
"id": "Node-1",
"label": "Node-1",
"image": "img/hosts.png",
"shape": "image",
"description": "Node-1:type: OS::Nova::Serverproperties: image: {get_param:image} flavor: {get_param:flavor}"
},
{
"id": "Switch-1",
"label": "Switch-1",
"image": "img/switch.png",
"shape": "image",
"description": "Switch-1:type: OS::Neutron::Netproperties: name:Switch-1Switch-1_subnet:"
}
]
alert(x[0].description)