Tom C Tom C - 1 year ago 96
JSON Question

JSON javascript display value undefined

I have a JSON object returned which looks like this

"competition": {
"name": "Premier League",
"nextState": 1,
"team_id": 1
}, {
"competition": {
"name": "Premier League",
"nextState": 1,
"team_id": 2

This a slimmed down version of the JSON, I am trying to access say the team_id

result = JSON.stringify(result, null, 4);



All I seem to get is undefined, am I not access this correctly?

Many thanks

Answer Source

You have stringified your object result to a string. So for sure you can not access the attributes anymore.

Use a second variable for the stringified result:

var result_stringified = JSON.stringify(result, null, 4);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download