如何获得JSON对象的价值如果名称中包含点? [英] How to get JSON objects value if its name contains dots?
本文介绍了如何获得JSON对象的价值如果名称中包含点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的JSON数组(请重点关注的points.bean.pointsBase对象):
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
但不幸的是,它什么都不显示。
当我更改points.bean.pointsBase以SMTH没有它的名字点 - 一切正常
但是,我不能这个名称更改为别的不点,但我需要得到一个值?
是否有任何选项得到它?
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?
推荐答案
你想要的是:
var smth = mydata.list[0]["points.bean.pointsBase"][0].time;
在JavaScript中,任何领域,您可以访问使用。运营商,您可以访问使用[]的字段名的字符串版本。
In JavaScript, any field you can access using the . operator, you can access using [] with a string version of the field name.
这篇关于如何获得JSON对象的价值如果名称中包含点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文