ajax parse,Ajax JSON Parse Error

Jquery 1.4 updated their JSON parser, so that it no longer accepts invalid JSON that it did before. Your server is outputting invalid JSON that was previously tolerated, but no longer is. This change was mentioned (briefly) in the release notes and documentation, and there's been lots of discussion about it if you google "jquery 1.4 JSON"

But to sum up: the keys in JSON, to be valid, must have quotes around them, the string can't be surrounded by those parentheses, and nothing can use single quotes as delimiters, so your JSON would need to be:

{"count": 5, "success": true, "error": "", "cache": false, "data": [{"column": ["Mike","Mike","Steve","Steve","Steve"]}]}

or, more readably:

{

"count": 5,

"success": true,

"error": "",

"cache": false,

"data": [

{

"column": [

"Mike",

"Mike",

"Steve",

"Steve",

"Steve"

]

}

]

}

The specs are very nicely and clearly spelled out at http://www.json.org/ with pictures and diagrams. You can also check your JSON at JSONLint - the JSON above checks out there just fine, but your original JSON raises all kinds of errors.

So as to what you need to do: if you have the ability to change what your server sends out, do that - make it output valid JSON. Please. Only if you are unable to change the server's behavior, you'll have to use a workaround from one of the posts linked above, or use some other JSON library.

General principle: in all cases, doing it the Right Way™ is preferable - fixing the server's output (even if that's filing a bug on an external server/API) is the long-term solution, but may not be immediately practical. So hackish workarounds are sometimes necessary, but not optimal.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值