json - 如何修复 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"
解决方案
推荐阅读
- javascript - JavaScript 中声明和填充的对象是未定义的错误
- google-sheets - 当键搜索是 URL 时 VLOOKUP 函数出现问题
- javascript - 无法使用我的方法使用 Excel 表导出数据
- c# - Azure 监控 REST API -(请求的名称有效,但未找到请求类型的数据。)
- python - 递归计算列表中的列表
- java - 如何在 Apache Camel 路由中再次读取跳过的文件?
- c# - 如何查询线程中的任务
- swift - Swift Firestore - 对文档 ID 进行编码,使其不会在 Firebase 中显示为单独的字段
- php - Laravel:为什么 Eloquent 显示隐藏字段?
- cypress - 从页面中获取文本,然后根据 API 调用对其进行验证