jQuery读取JSON文件内容的例子
来源:互联网 发布:vb6.0连接ms SQL 编辑:程序博客网 时间:2024/05/19 00:51
Json.html文件:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Json Document</title>
<script type="text/javascript" src="lib/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(function(){
$("#button").click(function(){
$.getJSON( b.json ,function(data){ //getJSON方法获得json文件的代码,其中的回调函数的参数data就是json代码
$("#json").empty(); //清空带“json” ID的div标签的内容
$.each(data,function(entryIndex,entry){ //each方法遍历json文件中的对象,entryIndex是当前索引,entry是当前项
var html="<div class= entry >";
html += "<h3 class= term >"+entry[ term ]+ </h3> ;
html += "<div class= part >"+entry[ part ]+"</div>";
html += "<div class= definition >"+entry[ definition ];
if(entry[ quote ]){
html+="<div class= quote >";
$.each(entry[ quote ],function(quoteIndex,line){
html+="<p>"+line+"</p>";
});
html+="</div>";
}
html+="</div>";
html +="</div>";
$("#json").append(html);
});
});
});
});
</script>
</head>
<body>
<div id="button"><b>Get Json Document</b></div>
<div id="json"></div>
</body>
</html>
b.json文件:
/*
* JSON File
* Website:http://www.supersha.cn
*autoor:沙锋
* This comment may need to be removed for proper parsing
*/
[
{
"term":"BACCHUS",
"part":"n.",
"definition":"A convenient deity invented by the ancients as an excuse for getting drunk.",
"quote":[
"Is public worship,then,a sin.",
"That for devotions paid to Bacchus",
"The lictors dare to run us in.",
"And resolutely thump and whack us?"
],
"author":"Jorace"
},
{
"term":"BACKBITE",
"part":"v.t.",
"definition":"To speak of a man as you find him when he can t find you."
},
{
"term":"BEARD",
"part":"n.",
"definition":"The hair that is commonly cut off by those who justly execrate the absurd Chinese custom of shaving the bead."
}
]
- jQuery读取JSON文件内容的例子
- jQuery ajax读取json文件内容
- jQuery ajax读取json文件内容
- jQuery读取JSON文件
- JQuery读取Json文件
- jQuery读取json文件
- jQuery中读取json文件
- jQuery中读取json文件
- JQuery读取本地Json文件
- JQuery读取本地JSON文件
- JQuery读取本地JSON文件
- 使用jQuery读取json文件
- JQuery读取本地json文件
- Java 小例子:读取文件内容
- Java 小例子:读取文件内容
- 文件内容的读取
- 读取文件的内容
- 将JSON内容写入并读取文件
- java 监听器
- 详解Excel互操作中处理数据的几个方法(上:读取数据)
- gridview1 binding 分页
- HTTP长连接服务器端推技术
- 09顺德国际家电博览会印象
- jQuery读取JSON文件内容的例子
- GridView中itemTemplate绑定字段的四种方式
- 太棒了!想学英语的好好留着!
- Thinking In Java:Characteristics of Object-Oriented
- ABAP 通过SQL修改某个程序的锁定状态
- 网页清除缓存方法
- 改变html select 选中
- asp.net中调用winrar实现压缩解压缩
- linux ssh 常用命令