Skip to content

Commit d914cfa

Browse files
committed
Merge branch 'hotfix/3.3.1' into release/3.4
Conflicts: WordPress/build.gradle
2 parents f834861 + 7967ee3 commit d914cfa

File tree

1 file changed

+22
-0
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+22
-0
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtil.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.wordpress.android.util.AppLog.T;
99

1010
import java.util.ArrayList;
11+
import java.util.Iterator;
1112

1213
public class JSONUtil {
1314
private static String QUERY_SEPERATOR=".";
@@ -231,4 +232,25 @@ public static JSONObject getJSONChild(final JSONObject jsonParent, final String
231232
}
232233
return jsonChild;
233234
}
235+
236+
// Returns a copy of the passed JSONObject
237+
@SuppressWarnings("unchecked")
238+
public static JSONObject copyJSONObject(JSONObject object) {
239+
JSONObject objectCopy = new JSONObject();
240+
241+
if (object == null) return objectCopy;
242+
243+
Iterator<String> iterator = object.keys();
244+
while (iterator.hasNext()) {
245+
try {
246+
String key = iterator.next();
247+
Object value = object.get(key);
248+
objectCopy.put(key, value);
249+
} catch (JSONException e) {
250+
AppLog.e(T.UTILS, e);
251+
}
252+
}
253+
254+
return objectCopy;
255+
}
234256
}

0 commit comments

Comments
 (0)