怎样将json格式的数据输出到html页面?
比如获得的json是这样:{"a":"内容1","b":"内容2","c":"内容3","d":"内容4",......}html是这样的:<tr><tdid="a"><...
比如获得的json是这样:
{"a":"内容1",
"b":"内容2",
"c":"内容3",
"d":"内容4",
......}
html是这样的:
<tr><td id="a"></td>
</tr>
<tr><td id="b"></td>
</tr>
<tr><td id="c"></td>
</tr>
<tr><td id="d"></td>
</tr>...... 展开
{"a":"内容1",
"b":"内容2",
"c":"内容3",
"d":"内容4",
......}
html是这样的:
<tr><td id="a"></td>
</tr>
<tr><td id="b"></td>
</tr>
<tr><td id="c"></td>
</tr>
<tr><td id="d"></td>
</tr>...... 展开
3个回答
2009-07-24
展开全部
var data = {"a":"内容1","b":"内容2","c":"内容3","d":"内容4",......};
document.getElementById("a").innerHTML = data["a"];
//以此类推
document.getElementById("a").innerHTML = data["a"];
//以此类推
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<html>
<head>
<meta
http-equiv=content-type
content="text/html;charset=GBK">
</head>
<body>
<table
border=0
cellspacing=0
cellpadding=0>
<tr>
<td
id="a">sdfsd</td>
</tr>
<tr>
<td
id="b">sdfsdf</td>
</tr>
<tr>
<td
id="c">sdfsd</td>
</tr>
<tr>
<td
id="d">sdfsdf</td>
</tr>
</table>
</body>
<script>
var
jsonStr
=
"{\"a\":\"内容1\",
\"b\":\"内容2\",\"c\":\"内容3\",\"d\":\"内容4\"}";
var
jsonObj
=
eval("("
+
jsonStr
+
")");
for(var
property
in
jsonObj){
var
nodeObj
=
document.getElementById(property);
if(nodeObj)
nodeObj.childNodes[0].nodeValue
=
jsonObj[property];
}
</script>
</html>
<head>
<meta
http-equiv=content-type
content="text/html;charset=GBK">
</head>
<body>
<table
border=0
cellspacing=0
cellpadding=0>
<tr>
<td
id="a">sdfsd</td>
</tr>
<tr>
<td
id="b">sdfsdf</td>
</tr>
<tr>
<td
id="c">sdfsd</td>
</tr>
<tr>
<td
id="d">sdfsdf</td>
</tr>
</table>
</body>
<script>
var
jsonStr
=
"{\"a\":\"内容1\",
\"b\":\"内容2\",\"c\":\"内容3\",\"d\":\"内容4\"}";
var
jsonObj
=
eval("("
+
jsonStr
+
")");
for(var
property
in
jsonObj){
var
nodeObj
=
document.getElementById(property);
if(nodeObj)
nodeObj.childNodes[0].nodeValue
=
jsonObj[property];
}
</script>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<html>
<head>
<meta http-equiv=content-type content="text/html;charset=GBK">
</head>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td id="a">sdfsd</td>
</tr>
<tr>
<td id="b">sdfsdf</td>
</tr>
<tr>
<td id="c">sdfsd</td>
</tr>
<tr>
<td id="d">sdfsdf</td>
</tr>
</table>
</body>
<script>
var jsonStr = "{\"a\":\"内容1\", \"b\":\"内容2\",\"c\":\"内容3\",\"d\":\"内容4\"}";
var jsonObj = eval("(" + jsonStr + ")");
for(var property in jsonObj){
var nodeObj = document.getElementById(property);
if(nodeObj)
nodeObj.childNodes[0].nodeValue = jsonObj[property];
}
</script>
</html>
<head>
<meta http-equiv=content-type content="text/html;charset=GBK">
</head>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td id="a">sdfsd</td>
</tr>
<tr>
<td id="b">sdfsdf</td>
</tr>
<tr>
<td id="c">sdfsd</td>
</tr>
<tr>
<td id="d">sdfsdf</td>
</tr>
</table>
</body>
<script>
var jsonStr = "{\"a\":\"内容1\", \"b\":\"内容2\",\"c\":\"内容3\",\"d\":\"内容4\"}";
var jsonObj = eval("(" + jsonStr + ")");
for(var property in jsonObj){
var nodeObj = document.getElementById(property);
if(nodeObj)
nodeObj.childNodes[0].nodeValue = jsonObj[property];
}
</script>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询