Make parseJSONObject/Array return null when parsing fails

This commit is contained in:
Ben Fry
2021-06-14 15:32:48 -04:00
parent 749e4d4d34
commit 53246fb23d
2 changed files with 15 additions and 2 deletions
+12 -2
View File
@@ -5629,7 +5629,12 @@ public class PApplet implements PConstants {
* @see PApplet#saveJSONObject(JSONObject, String)
*/
public JSONObject parseJSONObject(String input) {
return new JSONObject(new StringReader(input));
try {
return new JSONObject(new StringReader(input));
} catch (RuntimeException e) {
e.printStackTrace();
return null;
}
}
@@ -5741,7 +5746,12 @@ public class PApplet implements PConstants {
* @see PApplet#saveJSONObject(JSONObject, String)
*/
public JSONArray parseJSONArray(String input) {
return new JSONArray(new StringReader(input));
try {
return new JSONArray(new StringReader(input));
} catch (RuntimeException e) {
e.printStackTrace();
return null;
}
}
+3
View File
@@ -8,6 +8,9 @@ X https://github.com/processing/processing4/pull/183
X calling unregisterMethod() on dispose from dispose() means concurrent mod
o https://github.com/processing/processing4/pull/199
X modernized the code a bit, checked in a version that queues to avoid list issue
X Make parseJSONObject/Array return null when parsing fails
X https://github.com/processing/processing4/issues/165
X https://github.com/processing/processing4/pull/166
_ cursor(PImage) broken everywhere because PImage.getNative() returns null