I have this php:
<?php
$jsonarr = array("haha" => array("hihi'hih","hu\"huh"));
print json_encode($jsonarr);
This gives me
{"haha":["hihi'hih","hu\"huh"]}
Now, in JSON.parse this breaks with
Uncaught SyntaxError: Unexpected token h
at Object.parse (native)
, unless I double escape the backslash like this
var json = '{"haha":{"hihi\'hih":"hu\\\"huh"}}';
JSON.parse(json);
How can I get php to create a JSON parse compatible output?
Meanwhile, I did get this to work with double json_encoding the string in php based on this PHP's json_encode does not escape all JSON control characters like this, but wonder if there is some other way.
$jsonarr = array("haha" => array("hihi'hih","hu\"huh"));
print json_encode(json_encode($jsonarr));