【问题标题】:how to split up values in json with javascript?如何使用 javascript 拆分 json 中的值?
【发布时间】:2017-10-05 17:18:10
【问题描述】:

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

【问题讨论】:

  • 你如何加载 json
  • 您可以将 Json 分配给变量并将其作为数组中的属性读取。例如:Json[1]。描述

标签: javascript arrays json parsing jsonparser


【解决方案1】:

它是一个 JSON 对象数组,因此您可以访问这些 array objects using index.Read more on JavaScript Array

对于对象属性,您可以使用属性名称,也可以使用 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)
   

【讨论】:

    猜你喜欢
    • 2023-02-03
    • 1970-01-01
    • 2019-08-21
    • 2014-07-27
    • 2018-08-15
    • 2021-04-06
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多