这个“逃脱”我的原因。
JSON转义正斜杠,因此哈希 {a: "a/b/c"}
被序列化为 {"a":"a\/b\/c"}
而不是 {"a":"a/b/c"}
.
为什么?
最佳答案
JSON 不要求您这样做,它允许您这样做。它还允许您将“\u0061”用于“A”,但这不是必需的,就像 Harold L 指出的那样:
The JSON spec says you CAN escape forward slash, but you don't have to.
Harold L 于 2009 年 10 月 16 日 21:59 回答
允许 \/
在将 JSON 嵌入到 <script>
中时会有所帮助标签,不允许</
在字符串内部,就像 Seb 指出的那样:
This is because HTML does not allow a string inside a
<script>
tag to contain</
, so in case that substring's there, you should escape every forward slash.
Seb 于 2009 年 10 月 16 日 22:00 回答 (#1580667)
Microsoft 的一些 ASP.NET Ajax/JSON API 使用此漏洞添加额外信息,例如,日期时间将作为 "\/Date(milliseconds)\/"
发送. (呸)
https://stackoverflow.com/questions/1580647/