Giorgio Zanetti Giorgio Zanetti - 2 years ago 97
JSON Question

Cannot access part of my json

I have a php script returning json data like this:

"clients": [
"id": "1",
"registrationDate": "2011-01-01",
"rating": "6",
"registrationNote": "aaa",
"registrationComment": "bbb",
"fare": "160"
"id": "2",
"registrationDate": "2011-01-01",
"rating": "4",
"registrationNote": "xyz",
"registrationComment": "abc",
"fare": "160"
"stats": {
"resFounds": 2,
"resLimit": 4000,
"execTime": "0.00643",
"timeStamp": 1465018214

In a javascript function (let's name it 'showData') I can succesfully pass clients data to another function calling it that way
loadTemplate(my-template, data.clients)
, then next statement in 'showData' function try to access stats object like this
countBox.innerHTML = data.stats.resFound
but instead of 2 it returns 'undefined'.
What's wrong? How am I supposed to access data under 'stats' object ?

Answer Source

You need to do data.stats.resFounds instead of data.stats.resFound

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download