任何人都可以建议我如何计算Java中某些JSON数据对象的百分比?

时间:2015-11-19 22:56:59

标签: java swing adobe-analytics

回复:

{
    "report":{
        "type":"ranked",
        "elements":[
            {
                "id":"browser",
                "name":"Browser"
            },
            {
                "id":"operatingSystem",
                "name":"Operating System"
            }
        ],
        "reportSuite":{
            "id":"xyz",
            "name":"xyz | .com"
        },
        "period":"October 2015",
        "metrics":[
            {
                "id":"revenue",
                "name":"Revenue",
                "type":"currency",
                "decimals":2,
                "latency":xxxx,
                "current":false
            }
        ],
        "data":[
            {
                "name":"Google Chrome 45.0",
                "url":"",
                "counts":[
                    "450000.41"
                ],
                "breakdown":[
                    {
                        "name":"Windows 7",
                        "url":"",
                        "counts":[
                            "20000.00"
                        ]
                    },
                    {
                        "name":"OS X 10.10",
                        "url":"",
                        "counts":[
                            "35000.00"
                        ]
                    },
                    {
                        "name":"Windows 8.1",
                        "url":"",
                        "counts":[
                            "50000.00"
                        ]
                    },
                    {
                        "name":"Windows 10",
                        "url":"",
                        "counts":[
                            "37000.20"
                        ]
                    },
                    {
                        "name":"OS X 10.9.5",
                        "url":"",
                        "counts":[
                            "19000.25"
                        ]
                    },
                    {
                        "name":"Windows Vista",
                        "url":"",
                        "counts":[
                            "20000"
                        ]
                    }

                        ]
                    }
                ]
            }
        ],
        "totals":[
            "27217371.38"
        ],
        "version":"1.4.15.11"
    },
    "waitSeconds":"1.390",
    "runSeconds":"5.021"
}

1 个答案:

答案 0 :(得分:1)

我假设您在询问如何根据计数计算每个操作系统的整体百分比?算法很简单,计算每个对象的总计数,然后对任何给定的对象划分计数/总计数* 100.

如果您需要帮助解析实际的JSON数据,这里有一个很好的问题/答案:

How to parse JSON in Java