I am using simplejson
to decode the following json string.
Here is a demo written in Python:
from simplejson import loads
loads("""["\s"]""")
The decoder will throw:
JSONDecodeError: Invalid \escape
How to cope with this? The expected output is:
["\\s"]
Please use 4 back slashes to print a single back slash in the resultant JSON string. Two slashes turns into one slash and escapes C#'s string only, to escape JSON, you will need another two. Or use can use the @ string for simplification.
In JSON the only characters you must escape are \, ", and control codes. Thus in order to escape your structure, you'll need a JSON specific function.
Definition and Usage. The json_decode() function is used to decode or convert a JSON object to a PHP object.
"\s" is not a valid JSON escape string.
According to json.org, only the following escape are valid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With