neb*_*ous 9 escaping schema.org json-ld
JSON-LD 内容中的字符串值是否应该转义?例如,Google 建议使用以下内容为站点搜索提供提示:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://www.example-petstore.com/",
"potentialAction": {
"@type": "SearchAction",
"target": "https://query.example-petstore.com/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是,如果我网站的搜索 URL 包含多个查询参数怎么办?是否应该或可以转义目标值中的字符?例如:
"target": "https://query.example-petstore.com/search?foo=bar\u0026q={search_term_string}",
Run Code Online (Sandbox Code Playgroud)
在 JSON-LD 中进行标记时,同样的问题适用于几种常见的 schema.org 类型。Organization->sameAs 中的 Google+ 社交个人资料链接,例如:如果我的组织的个人资料是
https://plus.google.com/+BeardsAreSweet
Run Code Online (Sandbox Code Playgroud)
应该表示为:
"sameAs": ["https://plus.google.com/+BeardsAreSweet"]
Run Code Online (Sandbox Code Playgroud)
或者
"sameAs": ["https://plus.google.com/\u002bBeardsAreSweet"]
Run Code Online (Sandbox Code Playgroud)
更重要的是,这真的重要吗?
当 url 是 JSON 对象的一部分时,无需对其进行转义。有效的 url 字符串是有效的 JSON 字符串。JSON 字符串可以包含:
除 \ 或 " 或控制字符之外的任何 UNICODE 字符