復制代碼 代碼如下:
/*
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;
}