网页前端设计

http://www.86y.org

搜索文章

我的json获取数据实例,直接运行就可以看到了

用声音读出全文关注我吧
 2011/4/2 16:42:07 阅读次数:7942
开始一直用jq的ajax接收值也是字符但是没用过json数据。(所以一直都用切割的方法来做)听朋友们说JSon处理数据比较好,所以也加入了json这个行列了。快来看看吧。对AJAX比较接收处理数据比较好!力荐!...
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的json获取数据实例,直接运行就可以看到了</title>
<meta name="Keywords" content="直接运行就可以看到了" />
<meta name="Description" content="是一个免费提供代码分享的一个网站,有最全的SEO资料,及Div+css,javascript,SEO学习网页前端设计" />
<head>
<script>
var people = {
	"programmers": [
	{ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
  {"firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
  ],
  "authors": [
  { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
  { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
  { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
  ],
  "musicians": [
  { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
  { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
  ] 
}
var lxr = {"AREA":[{"df":"请选择国籍","lg":"中国" },{"dsf":"江西","dperson":"九江"},{"dsf":"广东","dperson":"汕头"}]};
//alert(lxr.AREA[0].df+"--"+lxr.AREA[0].lg);
//for(i=1;i<lxr.AREA.length;i++)
//alert(lxr.AREA[i].dsf+"--"+lxr.AREA[i].dperson);
//alert(people.authors[1].genre);
//alert(people.length);
var str="";
var str2="";
</script>
</head>
<body>
<div id="info"></div>
<div id="area"></div>
</body>
</html>
<script>
for(j=0;j<people.programmers.length;j++)
{
	str+="programmers第"+j+1+"个"+people.programmers[j].firstName+"--"+people.programmers[j].lastName+"--"+people.programmers[j].email+"<br>"
}
for(j=0;j<people.authors.length;j++)
{
	str+="authors第"+j+1+"个"+people.authors[j].firstName+"---"+people.authors[j].lastName+"---"+people.authors[j].genre+"<br>"
}
for(j=0;j<people.musicians.length;j++)
{
	str+="musicians第"+j+1+"个"+people.musicians[j].firstName+"---"+people.musicians[j].lastName+"---"+people.musicians[j].instrument+"<br>"
}

//alert(str);
str2+=lxr.AREA[0].df+"--"+lxr.AREA[0].lg+"<br>";
for(i=1;i<lxr.AREA.length;i++)
	str2+=lxr.AREA[i].dsf+"--"+lxr.AREA[i].dperson+"<br>";
document.getElementById("info").innerHTML=str;
document.getElementById("area").innerHTML=str2;
//alert(lxr.AREA[i].dsf+"--"+lxr.AREA[i].dperson);
//alert(people.authors[1].genre);
//alert(people.length);
</script>

大家有什么问题或技术上的想法可以在此与大家分享,也可以加入前端爱好者QQ群(141999928)一起学习进步:【幸凡前端技术交流群】
如需转载请注明出处:http://www.86y.org/art_detail.aspx?id=136【我的json获取数据实例,直接运行就可以看到了】幸凡学习网
0

如果您觉得本文的内容对您的学习有所帮助,捐赠与共勉,支付宝(左)或微信(右)

阅读全文内容关闭