Javascript Jquery 遍历Json的实现代码


Posted in Javascript onMarch 31, 2010
/* 
author: liulf 
function: 
var __db_cpcj=vCpcj; 
var __db_cp=vCp; 
var vCp={"cppage":[ 
{"cpdh":"A01000101","page":"1","ca":"1309-36-0","mc":"硫铁矿","ename":"Pyrite","bm":"黄铁矿"}, 
{"cpdh":"A01000201","page":"1","ca":"1309-36-0","mc":"硫精砂","ename":"Pyrite concentrate;Sulfur concentrate","bm":""}, 
{"cpdh":"A01000202","page":"1","ca":"1309-36-0","mc":"硫精矿粉","ename": 
"Powdered pyrite concentrate;Pyrites concentrate,powder;Sulfur concentrate,powder","bm":"硫精矿"}, 
{"cpdh":"A02000101","page":"1","ca":"","mc":"磷矿石","ename":"Phosphorus ore","bm":""}, 
{"cpdh":"A02000111","page":"2","ca":"","mc":"磷矿砂","ename":"Phosphorite grit","bm":""}, 
{"cpdh":"A02000201","page":"2","ca":"","mc":"磷矿粉","ename":"Phosphate rock powder","bm":""}, 
{"cpdh":"A03000101","page":"2","ca":"12447-04-0","mc":"硼矿石","ename":"Ascharite;Boric ore","bm":"硼镁矿"}, 
{"cpdh":"A04000101","page":"2","ca":"","mc":"钾长石","ename":"Potash feldspar;Potassium feldspars","bm":""}, 
{"cpdh":"A04000201","page":"2","ca":"12003-63-3","mc":"长石粉","ename":"Feldspar powder","bm":""}, 
{"cpdh":"A04000301","page":"2","ca":"","mc":"光卤石","ename":"Carnallite","bm":""} 
]} 
*/ 
function ObjSearch() 
{ 
this.kw = ''; 
this.searchCpcj= function() 
{ 
$(vCpcj).each(function(){ 
}); 
} 
this.searchCp = function() 
{ 
// var json = eval(vCp.cppage) 
// for(var i=0; i<json.length; i++) 
// { 
// alert(json[i].cpdh+" " + json[i].page) 
// break; 
// } 
$.each(vCp.cppage,function(index,content){ 
document.write('<div>'+content.cpdh+'</div><br />'); 
}); 
} 
}

js
如何遍历jsonc对象?其实方法很简单。
比如有如下json对象:
var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,”sex”:”女”,”old”:30};
遍历方法:
for(var p in obj) 
{ 
str = str+obj[p]+','; 
return str; 
}
Javascript 相关文章推荐
javascript 一些用法小结
Sep 11 Javascript
什么是DOM(Document Object Model)文档对象模型
Mar 05 Javascript
cookie在javascript中的使用技巧以及隐私在服务器端的设置
Dec 03 Javascript
Javascript计算两个marker之间的距离(Google Map V3)
Apr 26 Javascript
ie中js创建checkbox默认选中问题探讨
Oct 21 Javascript
JQuery+Ajax无刷新分页的实例代码
Feb 08 Javascript
javascript实现input file上传图片预览效果
Dec 31 Javascript
H5移动端适配 Flexible方案
Oct 24 Javascript
JavaScript中Object值合并方法详解
Dec 22 Javascript
JavaScript引用类型Date常见用法实例分析
Aug 08 Javascript
解决layui页面按钮点击无反应,也不报错的问题
Sep 29 Javascript
JavaScript find()方法及返回数据实例
Apr 30 Javascript
jquery+json实现的搜索加分页效果
Mar 31 #Javascript
EXTJS内使用ACTIVEX控件引起崩溃问题的解决方法
Mar 31 #Javascript
ExtJS TabPanel beforeremove beforeclose使用说明
Mar 31 #Javascript
十个优秀的Ajax/Javascript实例网站收集
Mar 31 #Javascript
javascript中的107个基础知识收集整理 推荐
Mar 29 #Javascript
jquery CSS选择器笔记
Mar 29 #Javascript
Tinymce+jQuery.Validation使用产生的BUG
Mar 29 #Javascript
You might like
PHP远程连接MYSQL数据库非常慢的解决方法
2008/07/05 PHP
mysql数据库差异比较的PHP代码
2012/02/05 PHP
PHP安全上传图片的方法
2015/03/21 PHP
通过MSXML2自动获取QQ个人头像及在线情况(给初学者)
2007/01/22 Javascript
js parentElement和offsetParent之间的区别
2010/03/23 Javascript
De facto standard 世界上不可思议的事实标准
2010/08/29 Javascript
nodejs npm包管理的配置方法及常用命令介绍
2014/06/05 NodeJs
JavaScript鼠标特效大全
2016/09/13 Javascript
Angular限制input框输入金额(是小数的话只保留两位小数点)
2017/07/13 Javascript
jQuery实现切换隐藏与显示同时切换图标功能
2017/10/29 jQuery
Nodejs 和 Electron ubuntu下快速安装过程
2018/05/04 NodeJs
vue.js input框之间赋值方法
2018/08/24 Javascript
使用PreloadJS加载图片资源的基础方法详解
2020/02/03 Javascript
[47:12]TFT vs Secret Supermajor小组赛C组 BO3 第三场 6.3
2018/06/04 DOTA
[00:05]ChinaJoy现场 DOTA2玩家高呼“CN DOTA BEST DOTA”
2019/08/04 DOTA
python判断windows隐藏文件的方法
2014/03/21 Python
使用Python的Flask框架表单插件Flask-WTF实现Web登录验证
2016/07/12 Python
Python使用pylab库实现画线功能的方法详解
2017/06/08 Python
Python之reload流程实例代码解析
2018/01/29 Python
Python 编码规范(Google Python Style Guide)
2018/05/05 Python
python pands实现execl转csv 并修改csv指定列的方法
2018/12/12 Python
python-tkinter之按钮的使用,开关方法
2019/06/11 Python
pandas 对group进行聚合的例子
2019/12/27 Python
使用 tf.nn.dynamic_rnn 展开时间维度方式
2020/01/21 Python
详解Django自定义图片和文件上传路径(upload_to)的2种方式
2020/12/01 Python
python 实现的车牌识别项目
2021/01/25 Python
CSS3,线性渐变(linear-gradient)的使用总结
2017/01/09 HTML / CSS
澳大利亚票务和娱乐市场领导者:Ticketmaster
2017/03/03 全球购物
一道SQL面试题
2012/12/31 面试题
职工运动会邀请函
2014/01/19 职场文书
电子工程专业毕业生求职信
2014/03/14 职场文书
爱护公共设施演讲稿
2014/09/13 职场文书
公司周年庆典标语
2014/10/07 职场文书
升学宴家长致辞
2015/07/27 职场文书
python之PySide2安装使用及QT Designer UI设计案例教程
2021/07/26 Python
Nginx使用ngx_http_upstream_module实现负载均衡功能示例
2022/08/05 Servers