开发者

JSON.stringify in Firefox and line breaks

开发者 https://www.devze.com 2023-02-06 19:24 出处:网络
I discovered, when Firefox\'s JS开发者_StackOverflow中文版ON.stringify function converts string with line breaks it converts \'\\n\' characters to \'\\u000a\'. And when this data comes to server via j

I discovered, when Firefox's JS开发者_StackOverflow中文版ON.stringify function converts string with line breaks it converts '\n' characters to '\u000a'. And when this data comes to server via jQuery.ajax.send instead of '\u000a' I see just a whitespace. Anyone ran into same problem? Point me in right direction, please.


The Unicode code point for a newline is U+000A. Firefox happens to choose to encode the newline into Unicode '\u000a', instead of shortening it to '\n'. According to the JSON spec, it's allowable to use the Unicode form.

Are you sure anything is actually wrong with the output? Any JSON library should be able to handle the '\u000a' just fine.

If you're debugging by wrapping the decoded JSON in HTML, a newline is equivalent to a space in places where whitespace is unimportant. E.g.

<div>this
example</div>

is equivalent to:

<div>this example</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号