I am having a problem where json can encode an array But then it can't properly decode it due to special characters.
I found this function on stackoverflow that tries to help:
function escapeJsonString($value)
{ # list from www.json.org: (\b backspace, \f formfeed)
$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
$result = str_replace($escapers, $replacements, $value);
return $result;
}
But it is only a list of characters, every time I get a new special character I have to manually deal with it and add it to the character and its replacement list.
How do I properly take care of this?