Have json
{dev: "что такое а потом \n новая строка"} How to send it to the server so that it comes with a newline character and not \n ? Now comes not a newline character, but a slash and n , which is also printed.
Have json
{dev: "что такое а потом \n новая строка"} How to send it to the server so that it comes with a newline character and not \n ? Now comes not a newline character, but a slash and n , which is also printed.
Unfortunately, what you want to do is impossible and it is in the order of things.
And this ( \n ) is normal!
When encoding JSON, the newline characters are specially escaped, since the characters in the string in the string are not allowed in JSON, and what you want to transfer will be invalid JSON and will cause an error when parsing.
This is required by the specification!
And vice versa: if you get JSON on the server with \n then after parsing JSON you will get back a normal string with a normal line-break character and no other special actions need to be taken. (In any case, in those libraries that I use - this is so)
In other words, what you put there, you will receive and you should not look at the intermediate result.
By the way, the validator does not pass a string key without quotes either.
Valid version will be as follows:
{ "dev": "что такое а потом \nновая строка" } Trust libraries to encode and decode JSON.
Source: https://ru.stackoverflow.com/questions/605591/
All Articles