JSON 解析错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1321595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:19:16  来源:igfitidea点击:

JSON Parsing Error

jsonparsingopen-flash-chart

提问by ariefbayu

I got problem. I have this JSONautomatically generated by Open Flash Chart php library. The problem is, OFC report JSON Parse Error [Syntax Error]while test result using http://www.jsonlint.com/report that my JSON is fine. But, w3c parserreport error too:(

我有问题。我有这个由 Open Flash Chart php 库自动生成的JSON。问题是,OFC 报告JSON Parse Error [Syntax Error]使用http://www.jsonlint.com/ 的测试结果报告我的 JSON 很好。但是,w3c 解析器也报告错误:(

Any help?

有什么帮助吗?

Here's the JSON:

这是JSON:

{
    "title": "Followers Trend",
    "elements": [
        {
            "type": "area_hollow",
            "fill-alpha": 0.35,
            "values": [

            ],
            "colour": "#5B56B6",
            "text": "Followers",
            "font-size": 12 
        } 
    ],
    "x_axis": {
        "colour": "#A2ACBA",
        "grid-colour": "#D7E4A3",
        "offset": false,
        "steps": 4,
        "labels": {
            "steps": 2,
            "rotate": "vertical",
            "colour": "#A2ACBA",
            "labels": [

            ] 
        } 
    },
    "x_legend": {
        "text": "Week Trend (2009-08-17 - 2009-08-24)",
        "style": "{font-size: 20px; color: #778877}" 
    },
    "y_axis": {
        "min": 0,
        "max": 150,
        "steps": 30 
    }
}

回答by ariefbayu

A few things I learned while playing with JSON is:

我在玩 JSON 时学到的一些东西是:

  • If you have validate the JSON on various JSON validation services and the result is GOOD. But, when you failed to evalit, try to wrap your JSON using (and )=> ({jsondata})

    var json = eval( "(" + jsonString + ")" );
    
  • NEVERbuild the JSON yourself. It's a gate to failure. Always use official or popular JSON library (depending on your language). For example:

  • To display and format JSON data, you can use JSONViewer.
  • 如果您在各种 JSON 验证服务上验证了 JSON 并且结果是好的。但是,当您失败eval时,请尝试使用(and )=>包装您的 JSON({jsondata})

    var json = eval( "(" + jsonString + ")" );
    
  • 永远不要自己构建 JSON。这是通往失败的大门。始终使用官方或流行的 JSON 库(取决于您的语言)。例如:

  • 要显示和格式化 JSON 数据,您可以使用JSONViewer

回答by Kevin Hakanson

I think the w3c parser is having issues, I couldn't even get it to parse this:

我认为 w3c 解析器有问题,我什至无法解析这个:

{
    "title" : "Followers Trend"
}

It gave me this error:

它给了我这个错误:

Validation errors:

lexer couldn't parse at "{
    "title" : "Followers Trend"
}"

回答by Kevin Hakanson

http://json.bloople.nethelps you visualise the code to find and correct errors.

http://json.bloople.net可帮助您可视化代码以查找和纠正错误。