Skip to content

Commit fb38ca4

Browse files
committed
JSON fixes for Shiffman
1 parent 9ead114 commit fb38ca4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

core/src/processing/core/PApplet.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6028,6 +6028,7 @@ public XML createXML(String name) {
60286028
}
60296029
}
60306030

6031+
60316032
/**
60326033
* @webref input:files
60336034
* @param filename name of a file in the data folder or a URL.
@@ -6043,6 +6044,7 @@ public XML loadXML(String filename) {
60436044
return loadXML(filename, null);
60446045
}
60456046

6047+
60466048
// version that uses 'options' though there are currently no supported options
60476049
/**
60486050
* @nowebref
@@ -6056,6 +6058,7 @@ public XML loadXML(String filename, String options) {
60566058
}
60576059
}
60586060

6061+
60596062
/**
60606063
* @webref input:files
60616064
* @brief Converts String content to an XML object
@@ -6070,6 +6073,7 @@ public XML parseXML(String xmlString) {
60706073
return parseXML(xmlString, null);
60716074
}
60726075

6076+
60736077
public XML parseXML(String xmlString, String options) {
60746078
try {
60756079
return XML.parse(xmlString, options);
@@ -6079,6 +6083,7 @@ public XML parseXML(String xmlString, String options) {
60796083
}
60806084
}
60816085

6086+
60826087
/**
60836088
* @webref output:files
60846089
* @param xml the XML object to save to disk
@@ -6104,6 +6109,12 @@ public JSONObject loadJSONObject(String filename) {
61046109
}
61056110

61066111

6112+
public JSONArray loadJSONArray(String filename) {
6113+
JSONTokener tokener = new JSONTokener(createReader(filename));
6114+
return new JSONArray(tokener);
6115+
}
6116+
6117+
61076118
/**
61086119
* @webref input:files
61096120
* @see Table
@@ -6884,8 +6895,9 @@ public InputStream createInputRaw(String filename) {
68846895
File file = new File(dataPath(filename));
68856896
if (!file.exists()) {
68866897
// next see if it's just in the sketch folder
6887-
file = new File(sketchPath, filename);
6898+
file = sketchFile(filename);
68886899
}
6900+
68896901
if (file.isDirectory()) {
68906902
return null;
68916903
}

core/src/processing/data/JSONArray.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public JSONArray() {
107107
* @param x A JSONTokener
108108
* @throws JSONException If there is a syntax error.
109109
*/
110-
protected JSONArray(JSONTokener x) {
110+
public JSONArray(JSONTokener x) {
111111
this();
112112
if (x.nextClean() != '[') {
113113
throw new RuntimeException("A JSONArray text must start with '['");
@@ -332,7 +332,7 @@ public boolean getBoolean(int index) {
332332
* @throws JSONException If there is no value for the index. or if the
333333
* value is not a JSONArray
334334
*/
335-
public JSONArray getArray(int index) {
335+
public JSONArray getJSONArray(int index) {
336336
Object object = this.get(index);
337337
if (object instanceof JSONArray) {
338338
return (JSONArray)object;
@@ -348,7 +348,7 @@ public JSONArray getArray(int index) {
348348
* @throws JSONException If there is no value for the index or if the
349349
* value is not a JSONObject
350350
*/
351-
public JSONObject getObject(int index) {
351+
public JSONObject getJSONObject(int index) {
352352
Object object = this.get(index);
353353
if (object instanceof JSONObject) {
354354
return (JSONObject)object;

0 commit comments

Comments
 (0)