Jekyll 破坏 JSON 文件。箭头(“=>”)而不是“:”
Jekyll ruining JSON file. Arrows ("=>") instead of ":"
我想在 Jekyll 草稿中用 d3.js 制作一个 chopleth。
但 Jekyll 不知何故改变了我的 JSON 文件
{"type":"FeatureCollection", "features":[{"type":"Feature", "id":"01",
至
{"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "id"=>"01",
我希望 jekyll 将我的 json 文件放入 d3.json() 函数中,如下所示:
d3.json({{site.data.us-states}}, function(json){
svg.selectAll("path") blah blah
us-states 是我的 us-states.json 文件,但他妈的 Jekyll 到处都是 =>
有人能帮帮我吗?
site
是 Jekyll global variable.
site.data
是一个 Ruby 散列,包含从 _data
目录中的 YAML 文件加载的数据。
site.data.us-states
是一个 Ruby 散列或数组,我假设。
d3.json
is a D3 function that fetches JSON。它不会将 Ruby 散列或数组转换为 JavaScript 对象。
在 Ruby 中,您可以通过调用 to_json
将散列或数组转换为 JSON。
在 JavaScript 中,您通过调用 JSON.parse
.
将 JSON 字符串转换为对象
我想在 Jekyll 草稿中用 d3.js 制作一个 chopleth。
但 Jekyll 不知何故改变了我的 JSON 文件
{"type":"FeatureCollection", "features":[{"type":"Feature", "id":"01",
至
{"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "id"=>"01",
我希望 jekyll 将我的 json 文件放入 d3.json() 函数中,如下所示:
d3.json({{site.data.us-states}}, function(json){
svg.selectAll("path") blah blah
us-states 是我的 us-states.json 文件,但他妈的 Jekyll 到处都是 =>
有人能帮帮我吗?
site
是 Jekyll global variable.
site.data
是一个 Ruby 散列,包含从 _data
目录中的 YAML 文件加载的数据。
site.data.us-states
是一个 Ruby 散列或数组,我假设。
d3.json
is a D3 function that fetches JSON。它不会将 Ruby 散列或数组转换为 JavaScript 对象。
在 Ruby 中,您可以通过调用 to_json
将散列或数组转换为 JSON。
在 JavaScript 中,您通过调用 JSON.parse
.