Using array via ofxJSON to draw shapes? HELP!

Hello there, I am using ofxJSON to parse data from Seattle’s Fire Dept (HERE) and I am trying to use the location (long,lat) to determine the position of circles on the screen.

I have managed to get it so that only the data from the current day is downloaded so it wont be ridiculous amounts of numbers, but my problem now is how to access this data and use it to draw with??

Very beginner question I realise, many thanks in advance!

Also more than happy to post the code here if any wants to see it etc…

Cheers,

Joe

Hi, I’m posting under this old question that unfortunately never got answered because it’s related to using arrays in ofxJSON.

How can I add and populate an array in an ofxJSONElement object?
The examples only show storing numbers and texts, not arrays or objects.

I’m trying to serialize a polyline and store it as JSON…

ofPolyline line;
glm::vec2 pos;

ofxJSONElement data;

data["x"] = pos.x; // works
data["y"] = pos.y; // works
//data["line"] = Json::arrayValue(); // ???
//for(auto & p : line) { /*add array entry here ???*/ }

You can treat anything like an array by using an integer as the key;

// Writing
for (int i = 0; i < 100; i++ ) json[i] = myVar; // another ofxJSONElement if you wish
// Reading
for (int i = 0; i < json.size(); i++) ofLog() << json[i]; // or .asString(), asBool() etc 

So in this case you could do;

ofxJSONElement json;
for (int i = 0; i < points.size(); i++) { 
  ofxJSONElement p; 
  p["x"] = points.x; 
  p["y"] = points.y; 
  json[i] = p; 
}
json.save("points.json", true);

Gets more complicated when trying to shift, append, delete elements etc, but it’s possible.

1 Like