這篇文章帶給大家的內容是關於json資料如何進行處理(程式碼實例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
如果name值為空歸為其它,如果數組長度大於15,超出15的部分歸為其它
adata = {"resolution":{"540x960":3,"1080x1920":4,"1080x2160":2,"720x1080":1}, "brand":{"":10}, "version":{"5.1.1":2,"7.0":2,"5.0.2":2,"7.1.1":2,"8.0.0":1,"4.4.4":1,"5.1":2,"7.1":2,"5.5.2":2,"":2,"8.0.1":1,"4.4":1,"5.6":2,"9.0":2,"6.0.2":2,"":2,"8.3":1,"4.7":1,"4.2":2,"9.6":1,"7.8.0":2}, "errorreason":{"":8,"APK Crash":2}}; getConfigData: function(category) { /*如果name值为空归为其它,如果数组长度大于15,超出15的部分归为其它*/ let adata = []; for (let i in category) { let a = 0, bdata = [], bbdata = []; for (let key in category[i]) { if (key == '') { a += category[i][key] bbdata.push({name: '其它', y: a}); } else { bdata.push({name: key, y: category[i][key]}); } } if (bdata.length > 15) { let b = 0; bdata.slice(0, -15).forEach(function(item) { b += item.y; }) bbdata[0].y = b + bbdata[0].y; bdata.splice(14,bdata.length-1,bbdata[0]) adata.push(bdata) }else{ adata.push(bdata.concat(bbdata)) } } return adata; }, getConfigData(adata);
以上是json資料如何進行處理(程式碼實例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!