Are multi-line strings allowed in JSON?

前端 未结 9 1319
醉酒成梦
醉酒成梦 2020-11-22 04:21

Is it possible to have multi-line strings in JSON?

It\'s mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I\'m just kinda curious

9条回答
  •  粉色の甜心
    2020-11-22 04:40

    JSON does not allow real line-breaks. You need to replace all the line breaks with \n.

    eg:

    "first line second line"

    can saved with:

    "first line\nsecond line"

    Note:

    for Python, this should be written as:

    "first line\\nsecond line"

    where \\ is for escaping the backslash, otherwise python will treat \n as the control character "new line"

提交回复
热议问题