我想列出以下结构后的数据:
the datas that published
today:
data1,
data2,
the datas that published
yesterday:
data1,
data2
我将以JSON格式获取数据。 JSON结构应该如何获取这样的数据?
HTML结构是:
<div class="list dark">
<div class="item item-divider">
today
</div>
<a class="item item-avatar-left" href="#">
<img src="image">
<h2>Tyrant</h2>
<p>desc</p>
</a>
<a class="item item-avatar-left" href="#">
<img src="image">
<h2>Tyrant</h2>
<p>desc</p>
</a>
<div class="item item-divider">
yestarday
</div>
<a class="item item-avatar-left" href="#">
<img src="image">
<h2>data</h2>
<p>desc</p>
</a>
</div>
答案 0 :(得分:0)
JSON的优点在于您可以随心所欲地构建它,以最适合您需求的方式。 (当然,假设您没有使用不受您控制的API。)
你今天和今天只会显示吗?如果是这样,您可能想要执行以下操作:
{
"today" : {
"image" : "url",
"data" : "your data",
"desc" : "description"
},
"yesterday" : {
"image" : "url",
"data" : "your data",
"desc" : "description"
}
}
或者,如果您可能要显示任意数量的日期,例如:
{
"dates": [
{
"date" : "2015-06-18",
"image" : "url",
"data" : "your data",
"desc" : "description"
},
{
"date" : "2015-06-17",
"image" : "url",
"data" : "your data",
"desc" : "description"
}
]
}