asd
asd

Reputation: 101

Reading JSON Name and Value

I want to read JSON objects's name value pair. Sample JSON below:

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "**menuitem**": [
      {"**value**": "New", "**onclick**": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}

As an example, if I want to read name "menuitem" and its values "value", "onclick". How is "menuitem" referred in this context?

Upvotes: 0

Views: 1034

Answers (1)

aprea
aprea

Reputation: 109

menu.popup.menuitem[0].value

menu.popup.menuitem[0].onclick

(you could also run through a loop if you wanted to get something rather than the first menuitem)

I assume there was asterisks in your code because you were trying to bold the sections in the json that you wanted to retrieve?

Also that json isn't valid, you're missing a closing }

Upvotes: 1

Related Questions