多行字符串作为Json中的值

时间:2018-12-10 23:06:31

标签: json

给出这个杰森

{
"myclass": {
    "studentname": "myname",
    "description": "Student has three more credits to complete\n
    he is taking maths\ n
    biology this semester "
 }
}

我在jsonlint中得到了'description'的Json解析器异常。更改描述以接受数组不是我的选择。

在Json中可以定义多行吗?

1 个答案:

答案 0 :(得分:1)

\n是唯一的方法。 JSON不是编程语言,您不能告诉它连接字符串。这也取决于上下文。

这将起作用

{
    "myclass": {
        "studentname": "myname",
        "description": "Student has three more credits to complete\nhe is taking maths\nbiology this semester"
     }
}

这不起作用

{
    "myclass": {
        "studentname": "myname",
        "description": "Student has three more credits to complete\n
                        he is taking maths\n
                        biology this semester"
     }
}