Json对象处理成数组

xiaoxiao2025-08-14  27

const obj = this.dataObj; let arr = []; Object.keys(obj).forEach(v => { let o = {}; o[v] = obj[v]; arr.push(o); }); console.log(arr); let alllist = []; for (let i in arr) { const list = []; let json = arr[i]; Object.keys(json).forEach(function(item, index) { this.push(item, json[item]); }, list); const listtow = []; let jsontow = list[1]; Object.keys(jsontow).forEach(function(itemtow, indextow) { this.push(itemtow, jsontow[itemtow]); }, listtow); let myobj = {}; let myarr = []; for (let s = 0; s < listtow.length; s = s + 2) { myobj = { name: listtow[s], value: UntilsApi.detailWan(Number(listtow[s + 1])) }; myarr.push(myobj); } let datapbj = { title: list[0], dataArray: myarr }; alllist.push(datapbj); } this.datalist = alllist; console.log(alllist); }

 

转载请注明原文地址: https://www.6miu.com/read-5034856.html

最新回复(0)