1

这是一个有效的 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;

失败..
有什么解决方案吗?

4

2 回答 2

2

{您在开头和}结尾都缺少 a :

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 ...)
于 2012-06-05T10:12:50.993 回答
1

不,它不是一个有效的 JSON 对象:

你可以在这里查看:http: //jsonlint.com/

Parse error on line 1: 
    "amerika":[{"server"
    ^
    Expecting '{', '['
于 2012-06-05T10:13:52.373 回答