json文件:
[
{"name":"哈哈··","email":"邮箱01","gender":"男","hobby":["上网","打球"]},
{"name":"呵呵··","email":"邮箱02","gender":"男","hobby":["网购","打球"]}
]
js代码:
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
//请求方式为get
type:"GET",
//json文件位置
url:"user.json",
//返回数据格式为json
dataType: "json",
//请求成功完成后要执行的方法
success: function(data){
//使用$.each方法遍历返回的数据date,插入到id为#result中
$.each(data,function(i,item){
var content=item.name+","+item.email+","+item.gender+
","+item.hobby[0]+","+item.hobby[1]+"</br>";
$("#result").append(content);
})
}
})
});
</script>