Closed
Description
I'm a bit confused on how to use json class with nested arrays. The following seems to work but I'm not sure its is the correct method. And, is it necessary to delete JsonObject and JsonArray on function complete.
...create json
JSON json;
JsonObject obj = json.createObject();
JsonArray j_array = json.createArray();
obj.setInt("name", name);
for(int i=0; i<num_items; i++) {
JsonObject obj1 = json.createObject();
obj1.setString("ssid", network.wifi[i].ssid);
obj1.setString("pwd", network.wifi[i].pwd);
j_array.addObject(obj1);
}
obj.setArray("wifi", j_array);
...read json - couldn't figure out how to do without using m_node
obj = json.parseObject(std::string(str));
j_array.m_node = cJSON_GetObjectItem(obj.m_node, "contact");
for(int i=0; i<j_array.size(); i++) {
j_array.getObject(i).getString("name").copy(name, sizeof(name);
}