-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSONUtils.java
More file actions
42 lines (37 loc) · 1.16 KB
/
Copy pathJSONUtils.java
File metadata and controls
42 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.jsonsync;
import com.jsonsync.JSONSyncRuntimeException;
import com.jsonsync.utils.json.JSONArray;
import com.jsonsync.utils.json.JSONException;
import com.jsonsync.utils.json.JSONObject;
/**
*
* @author Arnaud CAVAILHEZ
*/
class JSONUtils {
public static int indexOfObjectInJSONArray(Object o, JSONArray array) {
for (int i = 0; i < array.length(); i++) {
try {
if (array.get(i).equals(o)) {
return i;
}
} catch (JSONException ex) {
throw new JSONSyncRuntimeException("#indexOfObjectInJSONArray failed ", ex);
}
}
return -1;
}
public static JSONArray copyJSONArray(JSONArray array) {
try {
return new JSONArray(array.toString());
} catch (JSONException ex) {
throw new JSONSyncRuntimeException("Could not copy JSON", ex);
}
}
public static JSONObject copyJSON(JSONObject json) {
try {
return new JSONObject(json.toString());
} catch (JSONException ex) {
throw new JSONSyncRuntimeException("Could not copy JSON", ex);
}
}
}