JSON解析错误 [英] JSON Parsing Error
问题描述
我有问题. 我有此Flash ,它是由Open Flash Chart php库自动生成的.问题是,OFC报告JSON Parse Error [Syntax Error]
而使用 http://www.jsonlint.com/报告的测试结果我的JSON没问题.但是, w3c解析器也会报告错误:(>
有帮助吗?
这是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
}
}
我在使用JSON时学到的一些东西是:
-
如果您已经在各种JSON验证服务上验证了JSON,则结果为GOOD.但是,当
包装JSONeval
失败时,请尝试使用(
和)
=>({jsondata})
var json = eval( "(" + jsonString + ")" );
-
从不自己构建JSON.这是通往失败的大门.始终使用官方或流行的JSON库(取决于您的语言).例如:
- 在PHP上:使用 json_encode()
- 在Java Android上:使用 org.json.JSONObject
- JSON官方页面中列出了所有其他可与JSON一起使用的库.
- 要显示和格式化JSON数据,可以使用 JSONViewer .
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
}
}
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.
这篇关于JSON解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!