Multiline string as a value in Json

28 浏览
0 Comments

Multiline string as a value in Json

这个问题已经有了答案:

JSON中允许多行字符串吗?

给定这个Json:

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

我在jsonlint中会得到一个“description”的Json解析器异常。将“description”更改为接受数组对我不是一个选项。

是否有任何方法在Json中定义多行?

admin 更改状态以发布 2023年5月23日
0
0 Comments

\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"
     }
}

0