【问题标题】:How to convert json string value into an ArrayList and display the values in Android ListView [duplicate]如何将json字符串值转换为ArrayList并在Android ListView中显示值[重复]
【发布时间】:2012-11-09 09:27:59
【问题描述】:

这是我的 JSON 数组和对象。

{
"table1": [
    {
        "item_id": "1",
        "items": [
            "Veg Snacker",
            "Chicken Snacker",
            "Snack Box *1pc. Chicken & Fries",
            "Chicken Rizo",
            "Veg Stripes",
            "Popcorn Chicken"
        ]
    }
],
"success": 1
}

所以,我想将这个 items 字符串值显示到 android ListView 中。我试过分配,但我不能得到它。所以请如果有人知道如何将json 字符串值转换为ArrayList

我想要这样的输出:

Veg Snacker
Chicken Snacker
Snack Box..... ect,

【问题讨论】:

  • -1 你试过什么?

标签: android json


【解决方案1】:

这应该可以帮助您入门:

 String jsonString = "PUT JSON STRING HERE";
    JsonObject object = new JsonObject(jsonString);
    JsonArray tables = object.getJsonArray("table1");
    for(JsonObject value: tables){

        JsonArray items = value.getJsonArray("items");
        for(JsonObject item: items){
            Log.i("TAG",item.toString());
        }

    }

请记住,此解决方案没有任何错误处理。这个我也没有测试过,我就快写了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多