js解析json文件并生成对应的表格
用js将json文件的数据解析后,生成对应的表格$.getJSON("jsona.txt",function(json){vardatanav=json.people;v...
用js将json文件的数据解析后,生成对应的
表格
$.getJSON("jsona.txt", function(json){
var datanav=json.people;
var tb = document.getElementById("tb");
for (var i = 0; i < datanav.length; i++) {
var row = tb.insertRow(tb.rows.length);
var c1 = row.insertCell(0);
c1.innerHTML = datanav[i].firstName;
var c2 = row.insertCell(1);
c2.innerHTML = datanav[i].lastName;
var c3 = row.insertCell(2);
c3.innerHTML = datanav[i].email;}
});
能不能帮改一下这个代码? 展开
表格
$.getJSON("jsona.txt", function(json){
var datanav=json.people;
var tb = document.getElementById("tb");
for (var i = 0; i < datanav.length; i++) {
var row = tb.insertRow(tb.rows.length);
var c1 = row.insertCell(0);
c1.innerHTML = datanav[i].firstName;
var c2 = row.insertCell(1);
c2.innerHTML = datanav[i].lastName;
var c3 = row.insertCell(2);
c3.innerHTML = datanav[i].email;}
});
能不能帮改一下这个代码? 展开
展开全部
追问
数据是没有问题的,alert得了
追答
alert得来的数据,发上来看看,分析一下呗
展开全部
$("#tby tbody")写错了,$("#tby")就行
追问
不对啊,出不来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-08-12 · 知道合伙人互联网行家
关注
展开全部
简单实现代码:
1.用应用JS调用实现:
[javascript] view plaincopyprint?
function Json2Htm(s){
var htm="";
for(var i in s){
var template = "小题"+i;
for(var j in s[i]){
template +=" 第"+j+"格:"+s[i][j];
}
htm += template+"<br>";
}
return htm;
}
$(function(){
$(".buildHtm").each(function(){
var json=$(this).next();
json.hide();
eval('var s='+json.html());
$(this).html(Json2Htm(s));
});
});
2.应用HTML实现:
[html] view plaincopyprint?
</head>
<body>
<form id="form1" runat="server">
<div class="buildHtm" ></div>
<稿和asp:Label runat="server" ID="txtHtml" >此处从服务端读取json数据</asp:Label>
</form>
</body>
</html>
3.应用C#实现:
[csharp] view plaincopyprint?
protected void Page_Load(object sender, EventArgs e)
{
string json = "
{\"1\":{\"3\":\"风\",\"1\":\"一\"},\"2\":{\"3\":\尘指"戏\",\"1\":\"二\"},\"3\":
{\"3\":\"开\",\"1\":\"三\"},\"4\":{\"3\":\"平\",\"1\":\"四\"键兄盯},\"5\":{\"3\":
\"登\",\"1\":\"五\"},\"6\":{\"3\":\"清\",\"1\":\"六\"}}";
txtHtml.Text = json;
}
1.用应用JS调用实现:
[javascript] view plaincopyprint?
function Json2Htm(s){
var htm="";
for(var i in s){
var template = "小题"+i;
for(var j in s[i]){
template +=" 第"+j+"格:"+s[i][j];
}
htm += template+"<br>";
}
return htm;
}
$(function(){
$(".buildHtm").each(function(){
var json=$(this).next();
json.hide();
eval('var s='+json.html());
$(this).html(Json2Htm(s));
});
});
2.应用HTML实现:
[html] view plaincopyprint?
</head>
<body>
<form id="form1" runat="server">
<div class="buildHtm" ></div>
<稿和asp:Label runat="server" ID="txtHtml" >此处从服务端读取json数据</asp:Label>
</form>
</body>
</html>
3.应用C#实现:
[csharp] view plaincopyprint?
protected void Page_Load(object sender, EventArgs e)
{
string json = "
{\"1\":{\"3\":\"风\",\"1\":\"一\"},\"2\":{\"3\":\尘指"戏\",\"1\":\"二\"},\"3\":
{\"3\":\"开\",\"1\":\"三\"},\"4\":{\"3\":\"平\",\"1\":\"四\"键兄盯},\"5\":{\"3\":
\"登\",\"1\":\"五\"},\"6\":{\"3\":\"清\",\"1\":\"六\"}}";
txtHtml.Text = json;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询