谁知道json格式的内容怎样输出到html中??
比如获得的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>......
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> </head> <body> <table> <tr><td id="a"></td></tr> <tr><td id="b"></td></tr> <tr><td id="c"></td></tr> <tr><td id="d"></td></tr> </table> <script type="text/javascript"> <!-- var data='{"a":"内容1","b":"内容2","c":"内容3","d":"内容4"}'; var jsonData = eval("("+data+")"); for(var key in jsonData){ //alert(key+':'+jsonData[key]); if(document.getElementById(key)){ document.getElementById(key).innerHTML=jsonData[key]; } } //--> </script> </body></html>