I have the following PHP code:
$foo = new stdClass();
$foo->test='hello world';
$bar = new stdClass();
$bar->foo = json_encode($foo);
$encoded_string = json_encode($bar);
The $encoded_string
contains:
{"foo":"{\"test\":\"hello world\"}"}
I want to parse this string from javascript (using jQuery's $.parseJSON
for example):
var data = $.parseJSON('{"foo":"{\"test\":\"hello world\"}"}');
console.log(data);
I would expect something like the following to be logged:
Object {foo: '{"test":"hello world"}'}
But I get an Unexpected token t
error when running it (using chromium)
How can I parse this json string in Javascript? Here's a fiddle if anyone wants to try.