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 相关文章推荐
jquery获得下拉框值的代码
Aug 13 Javascript
jquery win 7透明弹出层效果的简单代码
Aug 06 Javascript
jQuery实现简单的文件上传进度条效果
Mar 26 Javascript
H5用户注册表单页 注册模态框!
Sep 17 Javascript
jQuery实现倒计时重新发送短信验证码功能示例
Jan 12 Javascript
JS返回顶部实例代码
Aug 09 Javascript
vue2.0在没有dev-server.js下的本地数据配置方法
Feb 23 Javascript
angular 内存溢出的问题解决
Jul 12 Javascript
Vue中使用 setTimeout() setInterval()函数的问题
Sep 13 Javascript
JS Math对象与Math方法实例小结
Jul 05 Javascript
详解微信小程序开发之formId使用(模板消息)
Aug 27 Javascript
微信小程序scroll-view隐藏滚动条的方法详解
Mar 25 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程序中的常见漏洞进行攻击
2006/10/09 PHP
在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.dll(附下载)
2010/05/04 PHP
限制ckeditor上传图片文件大小的方法
2013/11/15 PHP
PHP面向对象程序设计模拟一般面向对象语言中的方法重载(overload)示例
2019/06/13 PHP
JQUERY THICKBOX弹出层插件
2008/08/30 Javascript
JavaScript 组件之旅(三):用 Ant 构建组件
2009/10/28 Javascript
基于jquery的放大镜效果
2012/05/30 Javascript
jQuery 获取、设置HTML或TEXT内容的两种方法
2014/05/23 Javascript
jQuery中parents()方法用法实例
2015/01/07 Javascript
JS基于cookie实现来宾统计记录访客信息的方法
2015/08/04 Javascript
JavaScript实现的圆形浮动标签云效果实例
2015/08/06 Javascript
浅析Javascript中bind()方法的使用与实现
2016/05/30 Javascript
学习vue.js条件渲染
2016/12/03 Javascript
angular $watch 一个变量的变化(实例讲解)
2017/08/02 Javascript
Angular2环境搭建具体操作步骤(推荐)
2017/08/04 Javascript
详解react-native WebView 返回处理(非回调方法可解决)
2018/02/27 Javascript
vue中使用mxgraph的方法实例代码详解
2019/05/17 Javascript
Vue-cli3.x + axios 跨域方案踩坑指北
2019/07/04 Javascript
mock.js模拟前后台交互
2019/07/25 Javascript
vue点击自增和求和的实例代码
2019/11/06 Javascript
微信小程序实现登录注册功能
2020/12/29 Javascript
Python Tkinter基础控件用法
2014/09/03 Python
Python的math模块中的常用数学函数整理
2016/02/04 Python
Python数组遍历的简单实现方法小结
2016/04/27 Python
详解pyenv下使用python matplotlib模块的问题解决
2018/11/29 Python
python实现拼接图片
2020/03/23 Python
Python Tornado批量上传图片并显示功能
2020/03/26 Python
Python Django form 组件动态从数据库取choices数据实例
2020/05/19 Python
Django restful framework生成API文档过程详解
2020/11/12 Python
全球酒店预订网站:Hotels.com
2016/08/10 全球购物
酒店服务实习自我鉴定
2013/09/22 职场文书
小学教师听课制度
2014/02/01 职场文书
俞敏洪励志演讲稿
2014/04/29 职场文书
学法用法心得体会(2016推荐篇)
2016/01/21 职场文书
浅谈redis五大数据结构和使用场景
2021/04/12 Redis
Java 垃圾回收超详细讲解记忆集和卡表
2022/04/08 Java/Android