本篇文章给大家带来的内容是关于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中文网其他相关文章!