From 0afd26623c0fa44c3c36d3b70323fa97c248106a Mon Sep 17 00:00:00 2001 From: Lukas Treyer Date: Sun, 4 Oct 2015 23:17:30 +0200 Subject: [PATCH] JSONObject and JSONArray initialization: JSONObject(Map map) allows to initialize the JSONObject with a Map JSONArray(Collection collection) allows to initialize a JSONArray with a Collection --- JSONArray.java | 4 ++-- JSONObject.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/JSONArray.java b/JSONArray.java index b2717d9..3605411 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -151,10 +151,10 @@ public class JSONArray implements Iterable { * @param collection * A Collection. */ - public JSONArray(Collection collection) { + public JSONArray(Collection collection) { this.myArrayList = new ArrayList(); if (collection != null) { - Iterator iter = collection.iterator(); + Iterator iter = collection.iterator(); while (iter.hasNext()) { this.myArrayList.add(JSONObject.wrap(iter.next())); } diff --git a/JSONObject.java b/JSONObject.java index ed1159e..5d17cc7 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -243,12 +243,14 @@ public class JSONObject { * the JSONObject. * @throws JSONException */ - public JSONObject(Map map) { + public JSONObject(Map map) { this.map = new HashMap(); if (map != null) { - Iterator> i = map.entrySet().iterator(); + Set eSet = map.entrySet(); + @SuppressWarnings("unchecked") + Iterator> i = (Iterator>) eSet.iterator(); while (i.hasNext()) { - Entry entry = i.next(); + Entry entry = i.next(); Object value = entry.getValue(); if (value != null) { this.map.put(entry.getKey(), wrap(value));