I every language you need to escape certain characters within a string literal. In C++ the escape sequence starts with a \
and followed by an escaped value for the char to be represented.
In str1 = "\"address\":\"test \ 00001\",\"type\":\"Float\""
the \
(the one before 00001) is \040
(040
is for the white space space) which is an unknown escape sequence so this escape sequence is ignore, and will result in:
"address":"test \ 00001","type":"Float"
For str2 = "\"address\":\"test \\ 00001\",\"type\":\"Float\""
the \\
is a vlaid escape sequnce for \
and that results in:
"address":"test \ 00001","type":"Float"
For str3 = "\"address\":\"test \\\ 00001\",\"type\":\"Float\""
the \
(the one before 00001) is the same as in the first case. And \\
before it is valid. So it results in:
"address":"test \\ 00001","type":"Float"
For str4 = "\"address\":\"test \\\\ 00001\",\"type\":\"Float\""
the escape squeence is correct and resutls in:
"address":"test \\ 00001","type":"Float"
This string is then once again pares by the JSON parse, there \
is also used as beginning of the escape sequence, so after parsing this resulting "address":"test \\ 00001","type":"Float"
, you will get "test \ 00001"
for address
.
That's one of the reasons why you don't want to build a JSON representation of data manually.