We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I'm having trouble figuring how to load a JSON array from a url in Android mode:
JSONArray values;
void setup() {
size(400, 516);
smooth();
values = loadJSONArray("https://" + "data.cityofchicago.org/resource/t2qc-9pjd.json");
}
void draw() {
for (int i = 0; i < values.size (); i++) {
JSONObject congestion = values.getJSONObject(i);
Float lat = congestion.getFloat("_south");
Float lon = congestion.getFloat("_west");
Float speed = congestion.getFloat("current_speed");
}
}
When I compile, I always get an error from inside the Android tools. Does anyone know a solution to this?
Thanks!
Answers
also, the Internet permissions are checked
i've also tried this:
String lines[] = loadStrings("https://data.cityofchicago.org/resource/t2qc-9pjd.json"); JSONArray values = JSONArray.parse(lines[0]);
but i get a null result from the values array.
i have tried your code in java mode: it works android mode: same error for the method loadJSonArray(); seems that this method does not exist in android mode...
@jnchmbrs::
with the code below i can acceed (android mode) to the jsonArray; i have not tried but i think that you can convert the file to jsonArray...
@akenaton
OMG thank you so much!! This does work in Android mode.
cannot answer to this question!