2016-12-15 49 views
0

我想在值之间放置一行空格或空格。因为他们现在都离开了。如何在JSON中创建空白

我的例子:

data: JSON.stringify({ 
     "sessionID":xxxxx, 
     "synchronize":false, 
     "sourceRequest":{ 
     "numberOrigin":xxxxxx, 
     "type":"x", 
     "description":test + "\\n" + test2 "\\n" + test3 "\\n" + test4, 
     "userID":xxxxxxxx, 
     "contact":{ 
      "name":"xxxxxxxxxxxxxxxxx", 
      "phoneNumber":"xxxxxxxxxx", 
      "email":xxxx, 
      "department":"xxxxx" 
     }, 
+0

一些加号似乎不见了。你的意思是'test +“\\ n”+ test2 +“\\ n”+ test3 +“\\ n”+ test4'? –

+0

现在有什么问题? –

回答

2

"\\n"说把字符串字面\n - 2个字符。你应该使用"\n"来表示它的新行 - 1个字符。

注意如果在Windows记事本中查看,\n对于新行是不够的。

+0

正确!另外,关于在JSON中转义的源代码和文档,可直接在http://json.org/ –

+0

上获得。这项工作非常感谢@Daniel A. White –

0

一个简单的''(空格字符)就足以完成所需的任务,json键确实拥有一个字符串,如果需要更突出的东西可以使用'\ t',请参阅here以获取更多信息。

相关问题