I have a very simple JSON array (please focus on "points.bean.pointsBase" object):
var mydata =
{"list":
[
{"points.bean.pointsBase":
[
{"time": 2000, "caption":"caption text", duration: 5000},
{"time": 6000, "caption":"caption text", duration: 3000}
]
}
]
};
// Usually we make smth like this to get the value:
var smth = mydata.list[0].points.bean.pointsBase[0].time;
alert(smth); // should display 2000
But, unfortunately, it does display nothing.
When I change "points.bean.pointsBase" to smth without dots in it's name - everything works!
However, I can't change this name to anything else without dots, but I need to get a value?!
Is there any options to get it?
This question is related to
javascript
json
arrays
object
Just to make use of updated solution try using lodash utility https://lodash.com/docs#get
Try ["points.bean.pointsBase"]
If json object key/name contains dot......! like
var myJson = {"my.name":"vikas","my.age":27}
Than you can access like
myJson["my.name"]
myJson["my.age"]
in javascript, object properties can be accessed with . operator or with associative array indexing using []. ie. object.property
is equivalent to object["property"]
this should do the trick
var smth = mydata.list[0]["points.bean.pointsBase"][0].time;
Source: Stackoverflow.com