Multiline elements in JSON?

I would like to use JSON to send several variables, such as status, error message and contents, to the Javascript function via Ajax.

The problem I am facing is that I am retrieving the contents from the database, and almost all the data that is sent back to the browser is multi-line. And because of this, it seems that my JSON is not confirmed.

An outout example could be:

{ "status" : "ok", "message" : "All is well", "contents" : "Lorem Ipsum Dolor sit amet" } 

Is there any special way to handle a multi-line line that I missed, or is it just not possible (seems unlikely)?

Thanks!

+4
source share
1 answer

Since they are control characters, you cannot have literal newlines in JSON strings.

See specification: http://json.org/

The new lines are presented as \n , but you should not worry about this, because your JSON coding library should take care of this for you. Since you do not have a library with an error (in this case, I suggest correcting it, reporting it, or looking for an alternative), or you are not using the library (in this case, get it).

+3
source