This string
{\x22Address\x22:\x22some address with quotes \x22}
is parsed by JSON.parse correctly in browser. Why? What do hex numbers mean in json string? I can't find explanation.
This string
{\x22Address\x22:\x22some address with quotes \x22}
is parsed by JSON.parse correctly in browser. Why? What do hex numbers mean in json string? I can't find explanation.
In Javascript a backslash is an escape character. There are several escape sequences, you can find a list here.
The most important:
\x
followed by two hexadecimal characters represent a character by it's ascii code\u
followed by four hexadecimal characters represent a character by it's unicode number\t
, \r
, \n
you certainly know already. They are tab, carriage return and new line respectively.If you look up the hex value 22 in a ascii table, you can see that its the quote sign ( " ). Thats why its parsed correctly. http://www.asciitable.com/
var str= "{\x22test\x22: \x22hello\x22}";
var test = JSON.parse(str);
console.dir(test);
{ test: 'hello' }