需要访问JSON.stringify对象中的数据 [英] Need to access data in JSON.stringify object
问题描述
此问题的背景是我正在尝试从Google可视化日历中的addListener访问选定的单元格.我可以使用JSON.stringify(chart.getSelection());
打印选定的单元格.打印为[{"date":1468195200000,"row":0}]
.
The background for this question is I'm trying to access the selected cell from addListener in google visualization calendar. I could print the selected cell using JSON.stringify(chart.getSelection());
. It prints as [{"date":1468195200000,"row":0}]
.
我的问题是访问此日期对象.我尝试以
My problem is to access this date object. I tried to access it as
var obj=JSON.stringify(chart.getSelection());
console.log('selected value '+obj.date);
但是它显示为Undefined
.当我打印obj
时,它显示为[object,object]
But it displays as Undefined
. When I print the obj
it displays as [object, object]
如果您需要更多信息,请告诉我.任何建议,将不胜感激.
If you need more information please let me know. Any suggestion would be appreciated.
推荐答案
JSON.stringify()将数据对象序列化为字符串.只需直接访问对象即可.
JSON.stringify() serializes a data object into a string. Just access the object directly.
var data = chart.getSelection()[0]; // assuming there is only ever one item in the selection array.
console.log(data.date)
这篇关于需要访问JSON.stringify对象中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!