I am fairly new to Java and Processing, …coming from Javascript many things still look like black magic to me …
I am trying to format some data to JSON to send via websockets to an esp32 board. In JS its very straighforward since well, JSON is Javascript…
Here is a simplified version of my code:
// Variables
JSONObject json;
String jsonString;
String [][] myHexFrame;
int fps;
// These are inside a function
json = new JSONObject(); // Create a new JSON object. OK.
json.setInt("fps", fps); // Add a simple integer. Works no problem.
// json.setJSONArray("colors", myHexFrame); <-- The 2nd parameter should be... a JSONArray?
// How can I convert a "non JSON" array to a JSON one?
// Should I loop trough all values and push them one by one?
// Is there some kind of map() function to do that?
jsonString = json.toString(); // Stringify the whole thing. OK
ws.sendMessage(jsonString); // ..then send it. OK
The myHexFrame array was filled earlier in the code with hex values.