SkyWookie SkyWookie - 1 year ago 122
Javascript Question

JSON - how to get value in pure JS

I can't get any value from my JSON object.

I was trying:


It return undefined.
What am i doing wrong?

Validator say that JSON in valid.
Here is JSON object:

{"players": [
"player": {
"info": {
"position": "aaa",
"shirtNum": 1,
"positionInfo": "aaa"
"nationalTeam": {
"isoCode": "aaa",
"country": "aaa",
"demonym": "aaa"
"age": "221",
"name": {
"first": "aaa",
"last": "aaa"
"id": 111,
"currentTeam": {
"name": "aaa",
"teamType": "aaa",
"shortName": "aaa",
"id": 21

Answer Source

You probably have that json in a variable which I call theThing. You need to use theThing to gain access to your json.

var theThing =    JSON.parse('{"players":[{"player":{"info":{"position":"aaa","shirtNum":1,"positionInfo":"aaa"},"nationalTeam":{"isoCode":"aaa","country":"aaa","demonym":"aaa"},"age":"221","name":{"first":"aaa","last":"aaa"},"id":111,"currentTeam":{"name":"aaa","teamType":"aaa","shortName":"aaa","id":21}}}]}');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download