首页 > 解决方案 > 如何在 Android 中读取这种 json o/p?

问题描述

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

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

标签: phpandroidjson

解决方案


//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)");
     }
}

推荐阅读