Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在html文件中输出json对象?_Ruby On Rails_Ruby_Erb - Fatal编程技术网

Ruby on rails 如何在html文件中输出json对象?

Ruby on rails 如何在html文件中输出json对象?,ruby-on-rails,ruby,erb,Ruby On Rails,Ruby,Erb,我正在使用middleman生成HTML,我希望输出一个json ld对象,如下所示: <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "Person", "name": "John Doe", "jobTitle": "Graduate research assistant", "affiliation": "University of Dreams"

我正在使用middleman生成HTML,我希望输出一个json ld对象,如下所示:

<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>

{
“@context”:”http://schema.org",
“@type”:“Person”,
“姓名”:“约翰·多伊”,
“职位名称”:“研究生研究助理”,
“附属机构”:“梦想大学”,
“附加名称”:“约翰尼”,
“url”:”http://www.example.com",
“地址”:{
“@type”:“PostalAddress”,
“街道地址”:“桃花路1234号”,
“地址地点”:“仙境”,
“地区”:“格鲁吉亚”
}
}

我在一个对象中以正确的方式构造了数据,有没有好的方法输出它

要以正确的格式输出,应该如下所示:

%script{type: '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"
    }
  }
可能重复的