JQ and JS traversal JSON data method

Source: Internet
Author: User
The code is as follows Copy Code

/*
Author:liulf
function
var __DB_CPCJ=VCPCJ;
var __DB_CP=VCP;
var vcp={"Cppage": [
{"CPDH": "A01000101", "page": "1", "Ca": "1309-36-0", "MC": "Pyrite", "ename": "Pyrite", "BM": "Pyrite"},
{"CPDH": "A01000201", "page": "1", "Ca": "1309-36-0", "MC": "Sulfur fine Sand", "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 concentrates "},
{"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 ore powder", "ename": "Phosphate Rock powder", "BM": ""},
{"CPDH": "A03000101", "page": "2", "Ca": "12447-04-0", "MC": "Boron ore", "ename": "Ascharite; Boric ore "," BM ":" Boron magnesium ore "},
{"CPDH": "A04000101", "page": "2", "Ca": "", "MC": "Potash feldspar", "ename": "Potash feldspar;" Potassium feldspars "," BM ":" "},
{"CPDH": "A04000201", "page": "2", "Ca": "12003-63-3", "MC": "Feldspar powder", "ename": "Feldspar powder", "BM": ""},
{"CPDH": "A04000301", "page": "2", "Ca": "", "MC": "Carnallite", "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 ———————————

How do I traverse the Jsonc object? In fact, the method is very simple.

For example, you have the following JSON object:

The code is as follows Copy Code

var obj ={"name": "Feng Juan", "Password": "123456″," "Department": "Technical department", "Sex": "female", "old": 30};

Traversal method:

  code is as follows copy code

for (Var p in obj)

{

str = str+obj[p]+ ', ';
return str;

}

 

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.