Javascript Jquery 遍历Json的实现代码_json
程序员文章站
2022-04-28 16:12:21
...
复制代码 代码如下:
/*
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
// alert(json[i].cpdh+" " + json[i].page)
// break;
// }
$.each(vCp.cppage,function(index,content){
document.write('
'+content.cpdh+'
');
});
}
}
js
如何遍历jsonc对象?其实方法很简单。
比如有如下json对象:
var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,”sex”:”女”,”old”:30};
遍历方法:
复制代码 代码如下:
for(var p in obj)
{
str = str+obj[p]+',';
return str;
}
上一篇: ps怎么把选区边缘变得平滑
推荐阅读
-
javascript - Jquery ajax json 不执行success的原因
-
通过Jquery遍历Json的两种数据结构的实现代码_jquery
-
JavaScript实现的XML与JSON互转功能详解
-
jQuery实现可收缩展开的级联菜单实例代码_javascript技巧
-
Jquery+JSon 无刷新分页实现代码_jquery
-
js/jquery解析json和数组格式的方法详解_javascript技巧
-
用Json实现PHP与JavaScript间数据交换的方法详解_PHP
-
如何获取JQUERY AJAX返回的JSON结果集实现代码_基础知识
-
C#中的DataSet、string、DataTable、对象转换成Json的实现代码
-
C#解析json文件的实现代码