什么是将json文件转换为html输出的最佳方式将JSON转换为HTML表
我有一个输出一些json的脚本。我的JSON的样子:
[ { "description" : "desc 1 test",
"image" : "Http://test.com/gram.png",
"money" : null,
"title" : "title2"
},
{ "description" : "desc 2 test",
"image" : "http://test.com/daddy.gif",
"money" : "$7",
"title" : "title2"
},
{ "description" : "desc 3 test",
"image" : "test.com/41057.png",
"money" : null,
"title" : "title3"
}
]
我希望它吐出出来的东西像这样的下面(测试数据),但要注意的类是奇数和偶数 - 我不知道我怎么会去说。
<tr class="gradeA">
<td>title1</td>
<td class="center">image1</td>
<td class="center">desc1</td>
<td class="center">money1</td>
</tr>
<tr class="gradeA">
<td>title2</td>
<td class="center">image2</td>
<td class="center">desc2</td>
<td class="center">money2</td>
</tr>
<tr class="gradeA">
<td>title3</td>
<td class="center">image3</td>
<td class="center">desc3</td>
<td class="center">money3</td>
</tr>
<tr class="gradeA">
<td>title4</td>
<td class="center">image4</td>
<td class="center">desc4</td>
<td class="center">money4</td>
</tr>
但是你在你的例子所提供的类不是奇数和偶数? – Nightfirecat
您可以使用'$ res = json_decode($ json);'将其解码为一个php数组 –
它被称为'zebra striping',快速搜索该术语(也许在搜索术语中追加'CSS')会发现超过你的需要。 – Jasper