读取json时出错未捕获类型错误:Cannot read property 'output'的定义

Error while reading json Uncaught TypeError: Cannot read property 'output' of undefined

本文关键字:property read 定义 Cannot output 出错 json 错误 类型 读取      更新时间:2023-09-26

我正在尝试使用PUBNUB javascript SDK创建c3.js图表。问题是,当我尝试创建一个图表,它不会读取json数据,我得到错误Uncaught TypeError:无法读取属性'输出'的未定义。

完整的数据是(我正在通过python发送数据)

m = {
    "devices": [
        {
            "Name": "bdev0",
            "output": {
                "IO_Operations": 0,
                "Bytes_Read": 0,
                "Bytes_Written": 0
            }
        },
        {
            "Name": "bdev1",
            "output": {
                "IO_Operations": 0,
                "Bytes_Read": 0,
                "Bytes_Written": 0
            }
        }
    ]
}

而JavaScript是

eon.chart({
    pubnub   : pubnub,
    history  : false,
    channel  : 'chanel',
    flow     : true,
    generate : {
        bindto : '#chart_1',
        size: {
        height: 180,
        width: 500
    },
        data   : {
            x      : 'x',
            labels : true
        },
        axis : {
            x : {
                type : 'timeseries',
                tick : {
                    format : '%H:%M:%S'
                },
                zoom: {
                   enabled: true
                }
            }
        }
    },
    transform : function(m) {
        return { columns : [
            ['x', new Date().getTime()],
            ['Bytes Written', m.devices[i].output.Bytes_Read],
            ['Bytes Read', m.devices[i].output.Bytes_Written]

        ] };
    }
});

您正在使用devices[i],但是您没有定义 i是什么。你需要给i一个值,如果你要使用它作为一个数组索引。