Javascript Unexpected Token B中的JSON [英] JSON in Javascript Unexpected Token B

查看:101
本文介绍了Javascript Unexpected Token B中的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSON中解析以下字符串

I'm parsing the following string in JSON

http://jsfiddle.net/cjds/9mJbq/2/

当我运行它时,chrome会抛出以下错误意外的令牌B

When I run it chrome throws up the following error Unexpected Token B.

无法理解。因为字符串是由PHP json_encode创建的,所以JSON不应该有问题。

Can't figure it out. Because the string is created by PHP json_encode so there shouldn't be a problem with the JSON.

我通过JSONLint运行它并且没有错误因此JSON没问题。

I ran it through JSONLint and there was no error so the JSON is fine.

那么错误是什么?

推荐答案

JSON.parse()的参数应该是字符串。

The parameter for JSON.parse() should be string.

因此, JSON.parse([hello,world])是错误的。

它应该是 JSON.parse([\hello \,\world \])

我更新了jsfiddle。看看 http://jsfiddle.net/9mJbq/3/

I updated the jsfiddle. Take a look at http://jsfiddle.net/9mJbq/3/

这篇关于Javascript Unexpected Token B中的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆