JSON object to JS object

Source: Internet
Author: User

JSON data:

{        "YD1": 0,    "YD2": 0,    "YD3": 0,    "YD4": 0,    "YD5": 0,    "YD6": 0,    "YD7": 0,    "YD8": 0,    "YD9": 0,    "YD10": 0,    "YD11": 0,    "YD12": 0,    "GH1": 0,    "GH2": 0,    "GH3": 0,    "GH4": 0,    "GH5": 0,    "GH6": 0,    "GH7": 0,    "GH8": 0,    "GH9": 0,    "GH10": 0,    "GH11": 0,    "GH12": 0,    "KD1": 0,    "KD2": 0,    "KD3": 0,    "KD4": 0,    "KD5": 0,    "KD6": 0,    "KD7": 0,    "KD8": 0,    "KD9": 0,    "KD10": 0,    "KD11": 0,    "KD12": 0,    "TYGQ1": 0,    "TYGQ2": 0,    "TYGQ3": 0,    "TYGQ4": 0,    "TYGQ5": 0,    "TYGQ6": 0,    "TYGQ7": 0,    "TYGQ8": 0,    "TYGQ9": 0,    "TYGQ10": 0,    "TYGQ11": 0,    "TYGQ12": 0,}

The first method:

Js:

varYdarr = [],kdarr=[];functionAddjsonarr () { for(varIteminchBardatas) {//Bardatas refers to the JSON object to loop//Console.log (item);//Get Key//Console.log (Datajson[item]);//Get the value corresponding to the key         if(Item.indexof (' YD ') ==0) {//move the Add to Jsonarr array that begins with yd             varOBJ01 ={Obj1:bardatas[item]};         Ydarr.push (OBJ01); }         if(Item.indexof (' KD ') ==0) {//Hospitalityadd to Jsonarr array beginning with yd             varOBJ02 ={Obj1:bardatas[item]};         Kdarr.push (OBJ02); }} console.log (Ydarr);     Console.log (Kdarr); vardatas={}; Datas.ydarr= Ydarr;datas.kdarr =Kdarr; Storesalesline (' StoreSalesLine002 ', months, datas);//Line Chart ① first defines the global variable months=[],②ajax success Request months = Data.sort (). reverse (); ③ Data processing}

Echarts:

function Line (ID, months, datas) {x axis: data:monthsseries:[{data one: data:datas.ydarr},{Data II: DATA:DATAS.KDARR}]}

The second method:

Js:

functionCLine () {varDatas = {}; varyd = [], kd = [], GH = [], tygq = []; varmonths = []; Yd.push (Bardatas. YD1); Yd.push (Bardatas. YD2); Yd.push (Bardatas. YD3); Yd.push (Bardatas. YD4); Yd.push (Bardatas. YD5); Yd.push (Bardatas.    YD6); Yd.push (Bardatas. YD7); Yd.push (Bardatas. YD8); Yd.push (Bardatas. YD9); Yd.push (Bardatas. YD10); Yd.push (Bardatas. YD11); Yd.push (Bardatas.    YD12); Kd.push (Bardatas. KD1); Kd.push (Bardatas. KD2); Kd.push (Bardatas. KD3); Kd.push (Bardatas. KD4); Kd.push (Bardatas. KD5); Kd.push (Bardatas.    KD6); Kd.push (Bardatas. KD7); Kd.push (Bardatas. KD8); Kd.push (Bardatas. KD9); Kd.push (Bardatas. KD10); Kd.push (Bardatas. KD11); Kd.push (Bardatas.    KD12); Gh.push (Bardatas. GH1); Gh.push (Bardatas. GH2); Gh.push (Bardatas. GH3); Gh.push (Bardatas. GH4); Gh.push (Bardatas. GH5); Gh.push (Bardatas.    GH6); Gh.push (Bardatas. GH7); Gh.push (Bardatas. GH8); Gh.push (Bardatas. GH9); Gh.push (Bardatas. GH10); Gh.push (Bardatas. GH11); Gh.push (Bardatas.    GH12); Tygq.push (Bardatas. TYGQ1); Tygq.push (Bardatas. TYGQ2); Tygq.push (Bardatas. TYGQ3); Tygq.push (Bardatas. TYGQ4); Tygq.push (Bardatas. TYGQ5); Tygq.push (Bardatas.    TYGQ6); Tygq.puSH (bardatas. TYGQ7); Tygq.push (Bardatas. TYGQ8); Tygq.push (Bardatas. TYGQ9); Tygq.push (Bardatas. TYGQ10); Tygq.push (Bardatas. TYGQ11); Tygq.push (Bardatas.             TYGQ12);varyd1=/[yd0-9]/;//Regular, contains only yd and any 0-9 digits    varkd1=/[kd0-9]/; vargh1=/[gh0-9]/; vartygq1=/[tygq0-9]/;  for(varKeyinchBardatas) {        if(KEY.YD1) {//first set of data movementYd.push (Bardatas[key]); }        if(KEY.KD1) {//The second group of data loansKd.push (Bardatas[key]); }        if(KEY.GH1) {//The third set of data is an adageGh.push (Bardatas[key]); }        if(KEY.TYGQ1) {//The fourth set of data the sky is blueTygq.push (Bardatas[key]); }} datas.yd= yd; DATAS.KD = KD; Datas.gh = GH; Datas.tygq =Tygq; Storesalesline (' StoreSalesLine002 ', months, datas);//polylineConsole.log (Json.stringify (' Move: ' +yd)); Console.log (Json.stringify (' Loan: ' +kd)); Console.log (Json.stringify (' The proverb: ' +gh)); Console.log (Json.stringify (' Day one get green: ' +tygq)); }

Echarts:

function Line (ID, months, datas) {x axis: data:monthsseries:[{data one: data:datas.yd},{Data II: DATA:DATAS.KD}]}

JSON object to JS object

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.