We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everybody,
someone can explain me why this example, that I found in the reference, doesn't works!? at the end two errors are arised: "values.setJSONObject(i,animal) does not exist" and " json.setJSONArray() expect paramters like : String, JSONArray". maybe the second is a consequence of the first...then why the function ".setJSONObject()" does not exist (i don't found in the list) but is write in the example/reference?...how I can manage/create an JSONArray?...obviously I can create an array of "single" JSONObject. thanks
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
String[] names = { "Goat", "Leopard", "Zebra" };
JSONArray values;
void setup() {
values = new JSONArray();
for (int i = 0; i < species.length; i++) {
JSONObject animal = new JSONObject();
animal.setInt("id", i);
animal.setString("species", species[i]);
animal.setString("name", names[i]);
values.setJSONObject(i, animal);
}
saveJSONArray(values, "data/new.json");
}
Answers
https://Processing.org/download/
hi GoToLoop,
I had searched in the "report bugs" but with wrong "key word"...now I searched about " setJSONObject()" and I found #1827 and #1839...ok I understood. What I have now is that if I create a new sketch, and include the right example, it works...also after a "save as"; if I open my old sketch, already saved in the same directory, delete all and insert the right code this still not working (same errors)...why?...maybe is a dumb question but I don't found solution.
Your example seems to work fine for me.
Maybe you have an old version of Processing that didn't support these functions?
hi kevinWorkman,
I am using 3.3.6 on W10
you don’t have a size(660,650); command
I will try this:
values.setJSONObject(str(i), animal);
Kf
(Both arrays species and names should have the same length)
It works for me
It works for me without
str(i)
[from kfrajer]I extended the code so that the new file gets loaded as a test (mainly in
draw()
)I am on Win 10 / processing 3.3.7
Chrisir ;-)
Also note that there is a new forum
https://discourse.processing.org/categories
see also
https://forum.processing.org/two/discussion/28048/json-save-load#latest