Skip to content

Commit c8871cc

Browse files
committed
Merge pull request #190 from suheb/fix-issue189
Fixes: loadJSONObject and loadJSONArray are missing #189.
2 parents d4f8995 + 5d3c4c8 commit c8871cc

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

core/src/processing/core/PApplet.java

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4485,6 +4485,105 @@ public boolean saveXML(XML xml, String filename, String options) {
44854485
}
44864486

44874487

4488+
/**
4489+
* @webref input:files
4490+
* @param input String to parse as a JSONObject
4491+
* @see PApplet#loadJSONObject(String)
4492+
* @see PApplet#saveJSONObject(JSONObject, String)
4493+
*/
4494+
public JSONObject parseJSONObject(String input) {
4495+
return new JSONObject(new StringReader(input));
4496+
}
4497+
4498+
4499+
/**
4500+
* @webref input:files
4501+
* @param filename name of a file in the data folder or a URL
4502+
* @see JSONObject
4503+
* @see JSONArray
4504+
* @see PApplet#loadJSONArray(String)
4505+
* @see PApplet#saveJSONObject(JSONObject, String)
4506+
* @see PApplet#saveJSONArray(JSONArray, String)
4507+
*/
4508+
public JSONObject loadJSONObject(String filename) {
4509+
return new JSONObject(createReader(filename));
4510+
}
4511+
4512+
4513+
static public JSONObject loadJSONObject(File file) {
4514+
return new JSONObject(createReader(file));
4515+
}
4516+
4517+
4518+
/**
4519+
* @webref output:files
4520+
* @see JSONObject
4521+
* @see JSONArray
4522+
* @see PApplet#loadJSONObject(String)
4523+
* @see PApplet#loadJSONArray(String)
4524+
* @see PApplet#saveJSONArray(JSONArray, String)
4525+
*/
4526+
public boolean saveJSONObject(JSONObject json, String filename) {
4527+
return saveJSONObject(json, filename, null);
4528+
}
4529+
4530+
4531+
/**
4532+
* @nowebref
4533+
*/
4534+
public boolean saveJSONObject(JSONObject json, String filename, String options) {
4535+
return json.save(saveFile(filename), options);
4536+
}
4537+
4538+
4539+
/**
4540+
* @webref input:files
4541+
* @param input String to parse as a JSONArray
4542+
* @see JSONObject
4543+
* @see PApplet#loadJSONObject(String)
4544+
* @see PApplet#saveJSONObject(JSONObject, String)
4545+
*/
4546+
public JSONArray parseJSONArray(String input) {
4547+
return new JSONArray(new StringReader(input));
4548+
}
4549+
4550+
4551+
/**
4552+
* @webref input:files
4553+
* @param filename name of a file in the data folder or a URL
4554+
* @see JSONArray
4555+
* @see PApplet#loadJSONObject(String)
4556+
* @see PApplet#saveJSONObject(JSONObject, String)
4557+
* @see PApplet#saveJSONArray(JSONArray, String)
4558+
*/
4559+
public JSONArray loadJSONArray(String filename) {
4560+
return new JSONArray(createReader(filename));
4561+
}
4562+
4563+
4564+
static public JSONArray loadJSONArray(File file) {
4565+
return new JSONArray(createReader(file));
4566+
}
4567+
4568+
4569+
/**
4570+
* @webref output:files
4571+
* @see JSONObject
4572+
* @see JSONArray
4573+
* @see PApplet#loadJSONObject(String)
4574+
* @see PApplet#loadJSONArray(String)
4575+
* @see PApplet#saveJSONObject(JSONObject, String)
4576+
*/
4577+
public boolean saveJSONArray(JSONArray json, String filename) {
4578+
return saveJSONArray(json, filename, null);
4579+
}
4580+
4581+
4582+
public boolean saveJSONArray(JSONArray json, String filename, String options) {
4583+
return json.save(saveFile(filename), options);
4584+
}
4585+
4586+
44884587
public Table createTable() {
44894588
return new Table();
44904589
}

0 commit comments

Comments
 (0)