-1

i have some code json in here.

[ 
    {
      "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?

riki yudha
  • 35
  • 1
  • 7

1 Answers1

0

Its an Array of JSON objects so you can access those array objects using index.Read more on JavaScript Array

For the Object properties you can use name of property or you can loop through them using 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)
   
sumeet kumar
  • 2,628
  • 1
  • 16
  • 24