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 异步方法队列链实现代码分析
Jun 05 Javascript
JavaScript中OnLoad几种使用方法
Dec 15 Javascript
js利用数组length属性清空和截短数组的小例子
Jan 15 Javascript
jQuery简单实现QQ空间点赞已经取消点赞
Apr 02 Javascript
jquery实现可自动收缩的TAB网页选项卡代码
Sep 06 Javascript
js跨浏览器的事件侦听器和事件对象的使用方法
Dec 17 Javascript
JavaScript函数内部属性和函数方法实例详解
Mar 17 Javascript
小白谈谈对JS原型链的理解
May 03 Javascript
JQueryEasyUI之DataGrid数据显示
Nov 23 Javascript
easyui-datagrid特殊字符不能显示的处理方法
Apr 12 Javascript
vue 2.0路由之路由嵌套示例详解
May 08 Javascript
深入koa-bodyparser原理解析
Jan 16 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
smtp邮件发送一例
2006/10/09 PHP
Zend Framework中的简单工厂模式 图文
2012/07/10 PHP
php中用date函数获取当前时间有误的解决办法
2013/08/02 PHP
php url路由入门实例
2014/04/23 PHP
thinkPHP微信分享接口JSSDK用法实例
2017/07/07 PHP
PHP流Streams、包装器wrapper概念与用法实例详解
2017/11/17 PHP
JavaScript中的原型prototype完全解析
2016/05/10 Javascript
JS从数组中随机取出几个数组元素的方法
2016/08/02 Javascript
jquery插件treegrid树状表格的使用方法详解(.Net平台)
2017/01/03 Javascript
解决URL地址中的中文乱码问题的办法
2017/02/10 Javascript
angular十大常见问题
2017/03/07 Javascript
AngularJS实现自定义指令与控制器数据交互的方法示例
2017/06/19 Javascript
JavaScript变量作用域_动力节点Java学院整理
2017/06/27 Javascript
webpack多页面开发实践
2017/12/18 Javascript
jQuery实现ajax回调函数带入参数的方法示例
2018/06/26 jQuery
vue-cli点击实现全屏功能
2020/03/07 Javascript
jQuery HTML css()方法与css类实例详解
2020/05/20 jQuery
测试、预发布后用python检测网页是否有日常链接
2014/06/03 Python
python删除指定类型(或非指定)的文件实例详解
2015/07/06 Python
django-rest-swagger的优化使用方法
2019/08/29 Python
python tkinter图形界面代码统计工具(更新)
2019/09/18 Python
使用批处理脚本自动生成并上传NuGet包(操作方法)
2019/11/19 Python
python创建学生管理系统
2019/11/22 Python
Python使用Turtle库绘制一棵西兰花
2019/11/23 Python
matplotlib基础绘图命令之imshow的使用
2020/08/13 Python
Python urllib3软件包的使用说明
2020/11/18 Python
浅析rem和em和px vh vw和% 移动端长度单位
2016/04/28 HTML / CSS
简约控的天堂:The Undone
2016/12/21 全球购物
企业门卫岗位职责
2013/12/12 职场文书
中式结婚主持词
2014/03/14 职场文书
飘柔洗发水广告词
2014/03/14 职场文书
事业单位绩效考核实施方案
2014/03/27 职场文书
群众路线剖析材料
2014/09/30 职场文书
离婚协议书该怎么写
2014/10/04 职场文书
MyBatis配置文件解析与MyBatis实例演示
2022/04/07 Java/Android
Python使用openpyxl模块处理Excel文件
2022/06/05 Python