如何在Android中阅读这种json o / p?

时间:2018-05-14 21:22:45

标签: php android json

[
    {
        "hit": "1"
    },
    {
        "SUM(hit)": "196290"
    },
    {
        "COUNT(id)": "4010"
    }
]

如何在android中读取这种json o / p

1 个答案:

答案 0 :(得分:0)

//You can use below code for parsing this kind of jsonarray
String yourResponse;
JSONArray jsonarray = new JSONArray(yourResponse);
for (int i = 0; i < jsonarray.lenght(); i++){
     JSONObject jsonobject = jsonarray.getJSONObject(i);
     if(jsonobject.has("hit"){
        String hit = jsonobject.getString("hit");
     }
     if(jsonobject.has("SUM(hit)"){
        String sumHit = jsonobject.getString("SUM(hit)");
     }
     if(jsonobject.has("COUNT(id)"){
        String countID = jsonobject.getString("COUNT(id)");
     }
}