假设有一个具有这种格式的json:
{
"components":[
{
"id": "c3-1",
"type":"charts",
"component":"ChartC3Line",
"description":"Chart with round",
"picture": "/assets/img/components/chartc3-round.png",
"project": "yyy",
"date": "06-07-2015",
"dateupdate": "08-07-2015",
"status":" production"
},
{
"id": "c3-2",
"type":"charts",
"component":"ChartC3Date",
"description":"Chart with Date",
"picture": "/assets/img/components/chartc3-withdate.png
id: c3-2",
"date": "06-07-2015",
"project": "xxx",
"dateupdate": "08-07-2015",
"status":" production"
}]
}我希望能够用id: c3-2检索关于第二个对象的信息。
前提:
我怎样才能得到它的价值?举个例子。当然,我必须改变我的json文件的结构。
你将如何改变它?现在,我能够按索引获得正确的值:
{% assign comp = site.data.components.components[1] %}
{{ comp.component }}发布于 2015-09-11 20:26:26
您可以像这样构造您的数据/组件. like:
{
"c3-1" : {
"type":"charts",
"component":"ChartC3Line",
"description":"Chart with round"
},
"c3-2" : {
"type":"charts",
"component":"ChartC3Date",
"description":"Chart with Date"
}
}您现在可以通过他的id:{{ site.data.components["c3-1"] }}获得一个元素。
https://stackoverflow.com/questions/32519843
复制相似问题