如何将Json对象转换为HTML数据 [英] How to convert Json Object to HTML data
本文介绍了如何将Json对象转换为HTML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{a:1,b,3,我希望将它转换为HTML表格,如下所示:$ {
$ / code>
b
$ b
名称|价值
a 1
b 3
ds 4
有人可以提出一种如何在HTML中执行该操作的方法吗?
谢谢
解决方案
简单的jquery:
$ (function(){
var jsonObj = $ .parseJSON('{a:1,b:3,ds:4}');
var html = '< table border =1>';
$ .each(jsonObj,function(key,value){
html + ='< tr>';
html + ='< td>'+ key +'< / td>';
html + ='< td>'+ value +'< / td>';
html + =' < / tr>';
});
html + ='< / table>';
'('div')。html(html);
});
测试: http://jsfiddle.net/T7eQg/1/
编辑
<你可以使用这个js库。这个库通过排序等将json转换为表格:
http://www.dynatable.com/
I have a json object having data as :
{"a":1,"b",3,"ds",4}
I want to convert it into a HTML table like:
name|Value
a 1
b 3
ds 4
Can someone suggest a way how to do that in HTML?.
Thanks
解决方案
simple with jquery:
$(function(){
var jsonObj = $.parseJSON('{"a":1,"b":3,"ds":4}');
var html = '<table border="1">';
$.each(jsonObj, function(key, value){
html += '<tr>';
html += '<td>' + key + '</td>';
html += '<td>' + value + '</td>';
html += '</tr>';
});
html += '</table>';
$('div').html(html);
});
Test: http://jsfiddle.net/T7eQg/1/
EDIT
and you can use this js library. This library convert json to table with sort and etc: http://www.dynatable.com/
这篇关于如何将Json对象转换为HTML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文