JavascriptJquery implements Json traversal code _ json

Source: Internet
Author: User
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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.