JavascriptJquery traverses the Json implementation code. For more information, see.
The Code is as follows:
/*
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": "Sulfur Concentrate ", "ename": "Pyrite concentrate; Sulfur concentrate", "bm ":""},
{"Cpdh": "A01000202", "page": "1", "ca": "1309-36-0", "mc": "Sulfur Concentrate Powder ", "ename ":
"Powdered pyrite concentrate; Pyrites concentrate, powder; Sulfur concentrate, powder", "bm": "Sulfur concentrate "},
{"Cpdh": "A02000101", "page": "1", "ca": "", "mc": "phosphate ore", "ename ": "Phosphorus ore", "bm ":""},
{"Cpdh": "A02000111", "page": "2", "ca": "", "mc": "phosphate ore", "ename ": "Phosphorite grit", "bm ":""},
{"Cpdh": "A02000201", "page": "2", "ca": "", "mc": "phosphate rock powder", "ename ": "Phosphate rock powder", "bm ":""},
{"Cpdh": "A03000101", "page": "2", "ca": "12447-04-0", "mc": "Boron Ore ", "ename": "Ascharite; Boric ore", "bm": "Boron and magnesium "},
{"Cpdh": "A04000101", "page": "2", "ca": "", "mc": "Potash", "ename": "Potash feldspar; potassium feldspars "," bm ":""},
{"Cpdh": "A04000201", "page": "2", "ca": "12003-63-3", "mc": "Long powder ", "ename": "Feldspar powder", "bm ":""},
{"Cpdh": "A04000301", "page": "2", "ca": "", "mc": "Halogen Stone", "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
How to traverse jsonc objects? In fact, the method is very simple.
For example, the following json object is available:
Var obj = {"name": "Feng Juan", "password": "123456", "department": "technology department", "sex": "female", "old ": 30 };
Traversal method:
The Code is as follows:
For (var p in obj)
{
Str = str + obj [p] + ',';
Return str;
}