【问题标题】:How to get data from Array in android?如何从android中的Array获取数据?
【发布时间】:2015-07-24 09:36:24
【问题描述】:

我想从 android 的数组中获取数据。我在下面给出数组。告诉我如何在android中从这个数组中获取数据。我从 Parse 得到这个数组。

[
  {
    "name": "ajino motto",
    "qty": 30,
    "unit": "Gms"
  },
  {
    "name": "cobbige",
    "qty": 20,
    "unit": "Gms"
  },
  {
    "name": "salt",
    "qty": 0,
    "unit": "Gms"
  }
]

【问题讨论】:

标签: java android arrays arraylist


【解决方案1】:
String[] list;
for (int i = 0; i < array.size(); i++) {
    list[i]= array.get(i).getAsJsonObject().getAsJsonPrimitive("name").getAsString();
}

【讨论】:

  • 答案应该更详细。目前这是一个低质量的答案。
【解决方案2】:

试试这个方法

List<JSONObject> jsobj = new ArrayList<JSONObject>();

            jsobj = CommanClass.ParseObject_RecieptMaster
                    .getList(MainScreen.key_ingredientlist);

            for (int i = 0; i < jsobj.size(); i++) {
                Log.e("in the For loop ", ": : ::111111 : " + jsobj.get(i));

                JSONObject arr1 = new JSONObject((Map) jsobj.get(i)); // jsobj.get(i);
                Log.e("in the For loop ", ": : ::111111 : " + arr1);
                try {
                    Log.e("in the For loop ",
                            ": : ::111111 : " + arr1.getString("name"));

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

它在我的应用程序中完成的工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多