You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<Arduino_JSON.h>structMovie {
String title;
String director;
};
Movie movies[] {
{ "Raiders of the Lost Ark", "Ridley Scott" },
{ "Ghostbusters", "Steven Spielberg" },
{ "THX 1138", "George Lucas" }
};
voidsetup()
{
Serial.begin(9600);
// Wait for Serial or start after 2.5 secondsfor (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500));
// The JSON variable to host the JSON array for the movies
JSONVar jsonMovies;
// A simple index to iterate on while creating the JSON arrayint idx { 0 };
// Iterate on moviesfor (constauto& m : movies) {
// The JSON dictionary hosting the single movie element
JSONVar jm;
jm["title"] = m.title;
jm["director"] = m.director;
// Add the movie to the array
jsonMovies[idx] = jm;
idx++;
}
// The JSON variable hosting the root of the JSON
JSONVar jsonRoot;
// Add the movies array to the "movies" key
jsonRoot["movies"] = jsonMovies;
auto jsonString = JSON.stringify(jsonRoot);
Serial.println(jsonString);
}
voidloop()
{
}
Hi,
Is it possible to implement an array of objects with this library? If so, could you provide an example of implementing the following
Thank you
The text was updated successfully, but these errors were encountered: