JSONObject json;
JSONArray array;
JSONObject loc;
void setup() {
size(800, 800);
array = new JSONArray();
json = new JSONObject();
}
void draw() {
}
void keyPressed() {
if (key =='s') {
for (int i=0; i<3; i++) {
JSONObject newO = new JSONObject();
loc = new JSONObject();
add_Location(i);
newO.setInt("ID", i);
newO.setString("Attribute 1", "D");
newO.setString("Attribute 2", "G");
newO.setInt("Attribute 3", 2);
newO.setJSONObject("Attribute 4", loc);
newO.setString("Attribute 5", "DSP");
array.setJSONObject(i, newO);
}
json.setJSONArray("Object-Array", array);
saveJSONObject(json, "data/new.json");
}
}
void add_Location(int i) {
loc.setFloat(" X ", i * 202.4565);
loc.setFloat(" Y ", i * 255.2689);
}
I apologize in advance if this is very trivial. I am trying to save json array file with attributes of each
object in sequence. But they appear in random order in data file and not in the order they are added.
Is there any way to get them in sequence?