<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
var json = [
{
"empno": "001",
"ename": "李宁",
"job": "软件工程师",
"hiredate": "2020-7-15",
"salary": "9500"
},
{
"empno": "002",
"ename": "张三",
"job": "客户经理",
"hiredate": "2020-7-15",
"salary": "9500",
"customer": [
{
"cname": "王五"
},
{
"cname": "罗翔"
}
]
}
];
console.log(json);
for(var i=0; i<json.length; i++){
var emp = json[i];
document.write("<h1>");
document.write(emp.empno);
document.write("," + emp.job);
document.write("," + emp.hiredate);
document.write("," + emp.salary);
document.write("</h1>");
if(emp.customer != null){
document.write("<h2>");
for( var j=0; j<emp.customer.length; j++){
var customer = emp.customer[j];
document.write(customer.cname + ",");
}
document.write("</h2>");
}
}
</script>
<body>
</body>
</html>