JSON Parsing Error

 ̄綄美尐妖づ 提交于 2019-12-22 05:16:31

问题


I got problem. I have this JSON automatically 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 parser report error too:(

Any help?

Here's the 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 
    }
}

回答1:


A few things I learned while playing with JSON is:

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

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

    • On PHP: use json_encode()
    • On Java Android: use org.json.JSONObject
    • A list of all other available library to play with JSON is listed in JSON official page.
  • To display and format JSON data, you can use JSONViewer.



回答2:


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

{
    "title" : "Followers Trend"
}

It gave me this error:

Validation errors:

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



回答3:


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



来源:https://stackoverflow.com/questions/1321595/json-parsing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!