首页 > 解决方案 > 如何修复 Echarts 代码上的 JSON 验证错误

问题描述

我的 json 代码没有经过验证。我是 Javascript 新手。因此,我发现很难修复它。Json 代码如下所示。我正在使用此https://echarts.apache.org/examples/en/editor.html?c=line-simple中的示例-

json <- paste0("
option = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
    }]
};
")

json2 = gsub("\\s+", "", gsub('[\n\r]', "", json))
jsonlite::validate(json2)

错误

[1] "lexical error: invalid char in json text.\n                                       option={xAxis:{type:'category',\n                     (right here) ------^\n"

标签: jsonjsonlite

解决方案


推荐阅读