2015-11-19 43 views
-3

迴應:任何人都可以請建議我如何計算某些JSON數據對象在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" 
} 
+1

祝你好運。沒有努力=差的反應 –

回答

1

我以爲你是問如何計算整體的比例爲基於計數的每個OS?該算法很簡單,計算每個對象的總計數,然後針對任何給定的對象除以count/totalcounts * 100.

如果您需要幫助解析實際的JSON數據,那麼這是一個很好的問題/答案:

How to parse JSON in Java

+0

非常感謝。它有幫助 –