从Android的嵌套JSON获得价值,并通过它的ListView [英] get values from the nested json in android and pass it to listview

查看:175
本文介绍了从Android的嵌套JSON获得价值,并通过它的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下面的嵌套的JSON字符串获取值并将其传递给列表视图,我很困惑了。可能有人帮助它从这个problem.Thanks提前

JSON数据:

  {
    errstr:应用程序列表中,
    成功:1,
    数据:{
        topFree:[
            {
                的AppID:3,
                标题:rgrger
                价格:空,
                评分:
            },
            {
                的AppID:10,
                标题:dwdqw
                价格:空,
                评分:
            }
        ]
        topPaid:[
            {
                的AppID:14,
                标题:erfwerwe
                价格:0.00,
                评分:
            }
        ]
        周刊:[
            {
                的AppID:65,
                标题:wdfwfqw
                价格:0.00,
                评分:
            }
        ]
        书:,
        onlineApp:
    }
}


解决方案

试试这个..

  {尝试
    JSONObject的结果=新的JSONObject(响应);
    JSONObject的数据= result.getJSONObject(数据);    //检查你的条件...我现在直接调用数组..    如果(data.has(topFree){
        JSONArray阵列= data.getJSONArray(topFree);
        //用于存储值创建数组......你可以用你的类创建..
        arr_list =新的ArrayList<串GT;();        的for(int i = 0; I< array.length();我++){
        JSONObject的OBJ = array.getJSONObject(I)
            串的AppID =+ obj.getString(的AppID);
            字符串标题=+ obj.getString(标题);
            串价=+ obj.getString(价格);
            串等级=+ obj.getString(等级);
            arr_list.add(的AppID); //添加值数组。
        }
    }
   //做其他阵列相同}赶上(JSONException E){
    e.printStackTrace();
}

你会得到数据后..你可以添加值的ListView适配器。

i want to get the values from the below nested json string and pass it to listview, i'm confused about it. could somebody help it out from this problem.Thanks in advance

JSON DATA :

{
    "errstr": "Apps list",
    "success": 1,
    "data": {
        "topFree": [
            {
                "AppID": "3",
                "Title": "rgrger",
                "Price": null,
                "Rating": ""
            },
            {
                "AppID": "10",
                "Title": "dwdqw",
                "Price": null,
                "Rating": ""
            }
        ],
        "topPaid": [
            {
                "AppID": "14",
                "Title": "erfwerwe",
                "Price": "0.00",
                "Rating": ""
            }
        ],
        "magazine": [
            {
                "AppID": "65",
                "Title": "wdfwfqw",
                "Price": "0.00",
                "Rating": ""
            }
        ],
        "books": "",
        "onlineApp": ""
    }
}

解决方案

Try this..

try {
    JSONObject result = new JSONObject(response);
    JSONObject data = result.getJSONObject("data");

    // check for your conditions... i am directly calling array now..

    if(data.has("topFree"){
        JSONArray array = data.getJSONArray("topFree");
        //creating array for storing values... you caN create with your class..
        arr_list = new ArrayList<String>(); 

        for (int i = 0; i < array.length(); i++) {
        JSONObject obj = array.getJSONObject(i);
            String AppID = ""+obj.getString("AppID");
            String Title = ""+obj.getString("Title");
            String Price = ""+obj.getString("Price");
            String Rating = ""+obj.getString("Rating");
            arr_list.add(AppID); // adding values to array.
        }
    }
   // do the same for other arrays

} catch (JSONException e) {
    e.printStackTrace();
}

After you get data.. you can add values to listview adapter..

这篇关于从Android的嵌套JSON获得价值,并通过它的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆