谁能建议我如何计算 java 中某些 JSON 数据对象的百分比?

Can anyone please suggest me how to calculate percentage for certain JSON data Object in java?

回复:

{
    "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"
}

我假设你问的是如何根据计数计算每个 OS 占整体的百分比?该算法很简单,计算每个对象的总计数,然后对任何给定的对象除以计数/总计数 * 100。

如果您在解析实际 JSON 数据时需要帮助,这里有一个很好的 question/answer:

How to parse JSON in Java