【问题标题】:Uncaught TypeError: Cannot read property 'timestamp' of undefined未捕获的类型错误:无法读取未定义的属性“时间戳”
【发布时间】:2016-01-09 12:17:11
【问题描述】:

我是 hightcharts 的新手,我在 chrome 控制台上发现了一个错误。错误是“Uncaught TypeError: Cannot read property 'timestamp' of undefined”。以下是我的代码:

Javascript.JS:

if(selVal==str2[j]) {
    console.log("FOLDERNAME"+selVal);
    str3.push(str2[j+1]);
}

var json = str3[0];

**//This is for highcharts where I am trying to load myjson that is present in "var json"**
for (var k = 0; k < json.length; k++) {
    jsonArray.push({
    name: json[k].map.timestamp,**//Getting error over here**
    y:json[k].map.count
});

JSON 格式:

[{"map":{"timestamp":"2016-01-09 05:55:42.0","count":367}}]

请有人帮我解决这个问题。我几乎什么都试过了。

【问题讨论】:

  • 请正确格式化您的问题。它会增加你得到答案的机会。您也可以查看stackoverflow.com/help/how-to-ask
  • 您似乎尝试从字符串中获取属性,首先是parse json 字符串。 Check example
  • 欢迎来到 SO!请给我们更多代码以帮助您。 :)

标签: javascript jquery json highcharts


【解决方案1】:

试试这个

var json=[{"map":{"timestamp":"2016-01-09 05:55:42.0","count":367}}];

/***This is for highcharts where I am trying to load myjson that is present in "var json"**/
var jsonArray=[];
for (var k = 0; k < json.length; k++) {
    jsonArray.push({
    name: json[k]["map"].timestamp,
    y:json[k]["map"].count
    });
}
console.log(jsonArray)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-05
    • 2021-12-22
    • 2015-01-06
    • 2017-07-26
    • 2019-02-26
    • 2021-12-25
    相关资源
    最近更新 更多