如何在 html 文件中输出 json 对象?
Posted
技术标签:
【中文标题】如何在 html 文件中输出 json 对象?【英文标题】:How can i output a json-object inside a html-file? 【发布时间】:2015-10-02 05:10:08 【问题描述】:我正在使用中间人生成 html,我希望输出一个 json-ld-object,如下所示:
<script type="application/ld+json">
"@context": "http://schema.org",
"@type": "Person",
"name": "John Doe",
"jobTitle": "Graduate research assistant",
"affiliation": "University of Dreams",
"additionalName": "Johnny",
"url": "http://www.example.com",
"address":
"@type": "PostalAddress",
"streetAddress": "1234 Peach Drive",
"addressLocality": "Wonderland",
"addressRegion": "Georgia"
</script>
我在一个对象中以正确的方式构造了数据,有没有好的方法来输出它?
【问题讨论】:
***.com/questions/4464050/…的可能重复 【参考方案1】:要以正确的格式输出它应该是这样的:
%scripttype: 'application/ld+json'
:plain
"@context": "http://schema.org",
"@type": "Person",
"name": "John Doe",
"jobTitle": "Graduate research assistant",
"affiliation": "University of Dreams",
"additionalName": "Johnny",
"url": "http://www.example.com",
"address":
"@type": "PostalAddress",
"streetAddress": "1234 Peach Drive",
"addressLocality": "Wonderland",
"addressRegion": "Georgia"
【讨论】:
以上是关于如何在 html 文件中输出 json 对象?的主要内容,如果未能解决你的问题,请参考以下文章