-1

我在这里有一些代码 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 获取“描述”值?

4

1 回答 1

0

它是一个 JSON 对象数组,因此您可以访问这些array objects using index. 阅读更多关于 JavaScript 数组

对于对象属性,您可以使用属性名称,也可以使用循环遍历它们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)
   

于 2017-10-05T17:25:42.347 回答