阅读下面的JsonData.json文件并填充我的html表 [英] Read the JsonData.json file below and populate my html table

查看:80
本文介绍了阅读下面的JsonData.json文件并填充我的html表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要阅读下面的JsonData.json文件并在javascript中填充我的html表:



{

ID: 1,

姓名:John Smith,

IDNumber:7606015012088

},

{

ID:2,

名称:Molly Malone,

IDNumber:8606125033087< br $>
},





请帮忙,因为我是javascript的新手。

我的html是:



I need to read the JsonData.json file below and populate my html table in javascript:

{
"ID": 1,
"Name": "John Smith",
"IDNumber": "7606015012088"
},
{
"ID": 2,
"Name": "Molly Malone",
"IDNumber": "8606125033087"
},


Please help as I am very new to javascript.
My html is:

script src="jquery-1.10.2.min.js"></script>

<script type="text/javascript">

</script>





</head>
<body>
<h1>A JavaScript Test</h1>
<table>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>ID Number</th>
    </tr>
</table>
<p>

<button>Load Data</button>

推荐答案





首先,你的JSON文件不合适。它应该是这样的。



Hi,

First of all, your JSON file is not proper. It should be like this.

[{
"ID": 1,
"Name": "John Smith",
"IDNumber": "7606015012088"
},
{
"ID": 2,
"Name": "Molly Malone",
"IDNumber": "8606125033087"
}]



请考虑以下代码段。它将加载一个名为'jsondata.json'的json文件并创建一个表。


Consider following code snippet. It will load a json file called 'jsondata.json' and creates a table.

<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
	<script>
		function onLoad(){
			var url='jsondata.json';


.getJSON(url, function (json){
var table =
.getJSON(url, function(json){ var table =


< table>');
table.attr( ' border'' 1');
var tr =
('<table>'); table.attr('border','1'); var tr =


这篇关于阅读下面的JsonData.json文件并填充我的html表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆