这是一个有效的JSON对象吗?
serverStatus("amerika":
[{
"server": "1",
"ah_gold": "1",
"ah_hardcore": "1",
"ah_usd": "0",
"ah_aud": "0",
"ah_mxn": "0",
"ah_brl": "0",
"ah_clp": "0",
"ah_ars": "0"
}], "asien":
[{
"server": "1",
"ah_gold": "1",
"ah_hardcore": "1"
}], "europa":
[{
"server": "1",
"ah_gold": "1",
"ah_hardcore": "1",
"ah_eur": "0",
"ah_gbp": "0",
"ah_rub": "0"
}])
JSONP请求已成功完成,但在javascript中
var server = data.asien[0].server;
失败..
对此有何解决方案?
答案 0 :(得分:2)
您在开头没有{
,最后没有}
:
serverStatus({"amerika":[{"server":"1","ah_gold":"1","ah_hardcore":"1","ah_usd":"0","ah_aud":"0","ah_mxn":"0","ah_brl":"0","ah_clp":"0","ah_ars":"0"}],"asien":[{"server":"1","ah_gold":"1","ah_hardcore":"1"}],"europa":[{"server":"1","ah_gold":"1","ah_hardcore":"1","ah_eur":"0","ah_gbp":"0","ah_rub":"0"}]})
如果你对数字感兴趣,不要把它们放在引号之间,那是没用的。
最简单的测试对象是打开chrome开发人员工具并输入
console.log(... you object here ...)
答案 1 :(得分:1)
不,它不是有效的JSON对象:
您可以在此处查看:http://jsonlint.com/
Parse error on line 1:
"amerika":[{"server"
^
Expecting '{', '['