I have a vector which consist of a struct, see below:
struct FileInformation
{
String name;
size_t filesize;
};
std::vector<FileInformation> FileInformations;
How do I get JSON out of it the easiest way?
Using ArduinoJson:
DynamicJsonDocument doc(2048);
for (const FileInformation& item : FileInformations) {
JsonObject& obj = doc.createNestedObject();
obj["name"] = item.name;
obj["filesize"] = item.filesize;
}
serializeJson(doc, Serial);
This will produce a JSON document that looks like this:
[
{"name": "command.com", "filesize": 1234},
{"name": "config.sys", "filesize": 2345},
{"name": "autoexec.bat", "filesize": 3456}
]
Please read the tutorial for more information.
forcycle andprint?