diff --git a/core/src/processing/data/IntDict.java b/core/src/processing/data/IntDict.java index 9c9a2b943..dd6337b7e 100644 --- a/core/src/processing/data/IntDict.java +++ b/core/src/processing/data/IntDict.java @@ -660,8 +660,22 @@ public class IntDict { } + /** + * Return this dictionary as a String in JSON format. + */ + public String toJSON() { + StringList items = new StringList(); + for (int i = 0; i < size(); i++) { + items.append("\"" + keys[i] + "\": " + values[i]); + } + return "{ " + items.join(", ") + " }"; + } + + @Override public String toString() { + return getClass().getSimpleName() + " size=" + size() + " " + toJSON(); + /* StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName() + " size=" + size() + " { "); for (int i = 0; i < size(); i++) { @@ -672,5 +686,6 @@ public class IntDict { } sb.append(" }"); return sb.toString(); + */ } } diff --git a/core/todo.txt b/core/todo.txt index 58d325378..59916d171 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -2,6 +2,10 @@ X some Table cleanup based on other CSV parsing work X use StandardCharsets.UTF_8 instead of getting encoding by name X PApplet.main(Blah.class) now works +X add toJSON() method to IntDict +_ do the same for the other data classes +_ note the difference between this and toJSONObject() or toJSONArray() +_ or is that the better way to handle it? hm _ Can't render PGraphics object using image() within a PDF