【发布时间】:2013-06-15 05:56:59
【问题描述】:
我有以下 PHP 代码:
$foo = new stdClass();
$foo->test='hello world';
$bar = new stdClass();
$bar->foo = json_encode($foo);
$encoded_string = json_encode($bar);
$encoded_string 包含:
{"foo":"{\"test\":\"hello world\"}"}
我想从 javascript 中解析这个字符串(例如使用 jQuery 的$.parseJSON):
var data = $.parseJSON('{"foo":"{\"test\":\"hello world\"}"}');
console.log(data);
我希望记录如下内容:
Object {foo: '{"test":"hello world"}'}
但我在运行它时遇到Unexpected token t 错误(使用铬)
如何在 Javascript 中解析这个 json 字符串? Here's a fiddle如果有人想试试。
【问题讨论】:
标签: php javascript jquery json escaping