From f68bcc9e3468a312797eeca2ad42456b30d7c648 Mon Sep 17 00:00:00 2001 From: mtanana Date: Tue, 25 Jun 2013 20:16:54 -0500 Subject: [PATCH 1/2] Update JSONObject.java --- JSONObject.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index 5ca5a45bc..e011e669f 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -387,9 +387,9 @@ public JSONObject accumulate(String key, Object value) throws JSONException { testValidity(value); Object object = this.opt(key); if (object == null) { - this.put(key, - value instanceof JSONArray ? new JSONArray().put(value) - : value); + //this is the modified line The old version would put the raw value + //this forces an array when the accumulate version is used + this.put(key, new JSONArray().put(value)); } else if (object instanceof JSONArray) { ((JSONArray) object).put(value); } else { From 5473d322ba0e8112736d1e1c0d11f7abe7411061 Mon Sep 17 00:00:00 2001 From: mtanana Date: Wed, 26 Jun 2013 00:53:47 -0500 Subject: [PATCH 2/2] Update JSONObject.java I don't know if anyone wants this (or whether it violates JSON standards) but I've found that when I use JSONObject.accumulate I want to force an array object. This saves from having to write checking code on the client side to see if the item is an object or an array. You can just iterate over it the same way (because sometimes collections only have one item). In any case, this mod does it, but I suspect this function may have been written this way on purpose. Anyway, I love and depend on this library so thanks for keeping it maintained. --- JSONObject.java | 1 + 1 file changed, 1 insertion(+) diff --git a/JSONObject.java b/JSONObject.java index e011e669f..4e51ed389 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -389,6 +389,7 @@ public JSONObject accumulate(String key, Object value) throws JSONException { if (object == null) { //this is the modified line The old version would put the raw value //this forces an array when the accumulate version is used + this.put(key, new JSONArray().put(value)); } else if (object instanceof JSONArray) { ((JSONArray) object).put(value);