I have a stdClass
object in PHP, something like
$o = new stdClass;
$o->foo = $bar
The variable $bar
contains a
Seems as through the best answer to this question lies in another question.
To sum up, PHP's JSON encoder escapes all non ASCII characters, so newlines/carriage returns can't be inserted to bollacks up the Javascript string portion of the JSON property. This may not be true of other JSON encoders.
However, passing in a raw string to JSON encode can lead to the usual litany of XSS attacks, the following combination of constants is suggested.
var v= ;
or ensure the variable passed to json_encode
is really an object.