簡體   English   中英

如何轉換HashMap<String, JSONObject> 對象到 JSONArray

[英]How to convert HashMap<String, JSONObject> object into JSONArray

我有帶有 jsonobject 的 HashMap 我想將所有這些值存儲到 JSONArray 中。

是否可以 ?

請幫我。

假設你有兩個 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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM