我有以下 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 解析这个字符串($.parseJSON
例如使用 jQuery):
var data = $.parseJSON('{"foo":"{\"test\":\"hello world\"}"}');
console.log(data);
我希望记录如下内容:
Object {foo: '{"test":"hello world"}'}
但是Unexpected token t
运行它时出现错误(使用铬)
如何在 Javascript 中解析这个 json 字符串?如果有人想尝试,这里有一个小提琴。