Convert JSON String to JSON Object and Parse all data

could you cut down your code to what is your question please?

possibly start with the content of your msg?
put it in a file and skip all the network things.
? is that correct ?

[
  {"value": "[[ 40.0, 20.0, 0.0 ], [ 20.0, 40.0, 0.0 ], [ 60.0, 40.0, 0.0 ]]"},
  {"value": "[[ 140.0, 120.0, 0.0 ], [ 220.0, 420.0, 0.0 ], [ 60.0, 410.0, 0.0 ]]"},
  {"value": "[[ 10.0, 20.0, 0.0 ], [ 300.0, 220.0, 0.0 ], [ 40.0, 340.0, 0.0 ], [ 92.0, 20.0, 0.0 ]]"}
]

and the problem you might have is,
that inside are JSONObjects “value” what are string and not JSONArrays
the " [[],[]]" there should actually be no “”

_ OR ________________

JSONArray vectors, value,segments;
JSONObject vector;
String valuearrays;

String filename="data/vectors.json";

void setup() {
  vectors = loadJSONArray(filename);
  println(vectors);
  for (int i = 0; i < vectors.size(); i++) {
    vector = vectors.getJSONObject(i);
    println("i "+i+"_"+vector);
    valuearrays = vector.getString("value");
    //println(valuearrays);
    value = JSONArray.parse(valuearrays);
    //println(value);   
    for (int j = 0; j < value.size(); j++) {
      segments=value.getJSONArray(j);
      println("i "+i+" j "+j+"_"+segments);
    }
  }
}

1 Like