【问题标题】:How to convert HashMap<String, JSONObject> object into JSONArray如何将 HashMap<String, JSONObject> 对象转换为 JSONArray
【发布时间】:2015-06-27 04:18:04
【问题描述】:

我有带有 jsonobject 的 HashMap 我想将所有这些值存储到 JSONArray 中。

有可能吗?

请帮帮我。

【问题讨论】:

  • 不清楚的问题。 Map 和 Array 是两种根本不同的数据类型。 如何进行映射? (提示:首先将 [Hash]Map 转换为适当的 List - 至少在概念上 - 然后转换为 JSONArray。)
  • 您能举个例子吗?这对我很有帮助。
  • "应该如何进行映射?" - 不是没有得到回答。

标签: android arrays hashmap


【解决方案1】:

假设你有两个 json 对象存储在 hashmap 中:

HashMap<String, JSONOnject> stringJson = new HashMap<String, JSONObject>();
stringJson.put("key", jsonobject1);
stringJson.put("key1", jsonobject2); //remember the hashmap structure, its key value structure.

你可以通过hashmap的get方法来访问这个jsonObject:

JSONArray jarray = stringjson.get("key").getJsonArray("json array name"); //stringjson.get("key") will return jsonObject you stored.

但是您可以直接执行此操作,而无需将 json 对象保存到 hashmap。

【讨论】:

    猜你喜欢
    • 2019-02-03
    • 1970-01-01
    • 2011-11-03
    • 2018-01-07
    • 2016-06-05
    • 2016-02-09
    • 2020-06-11
    • 2013-06-27
    • 1970-01-01
    相关资源
    最近更新 更多