简体   繁体   English

如何使用javascript拆分json中的值?

[英]how to split up values in json with javascript?

i have some code json in here.我这里有一些代码 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:"
     }
]

how can i get the "description" value with javascript?如何使用 javascript 获取“描述”值?

Its an Array of JSON objects so you can access those array objects using index .它是一个 JSON 对象数组,因此您可以array objects using index访问这些array objects using index Read more on JavaScript Array 阅读有关 JavaScript 数组的更多信息

For the Object properties you can use name of property or you can loop through them using Object.keys or Object.getOwnPropertyNames()对于对象属性,您可以使用属性名称,也可以使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM