Replaced printTo() with serializeJson()

* Added `serializeJson()` and `serializeJsonPretty()`
* Added `measureJson()` and `measureJsonPretty()`
* Removed `printTo()` and `prettyPrintTo()`
* Removed `measureLength()` and `measurePrettyLength()`
This commit is contained in:
Benoit Blanchon
2018-03-01 09:24:58 +01:00
parent 7a2a64803a
commit 83d73c93f7
38 changed files with 238 additions and 233 deletions

View File

@ -72,7 +72,7 @@ void saveConfiguration(const char *filename, const Config &config) {
root["port"] = config.port;
// Serialize JSON to file
if (root.printTo(file) == 0) {
if (serializeJson(root, file) == 0) {
Serial.println(F("Failed to write to file"));
}

View File

@ -38,13 +38,13 @@ void setup() {
data.add(48.756080);
data.add(2.302038);
root.printTo(Serial);
serializeJson(root, Serial);
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
Serial.println();
root.prettyPrintTo(Serial);
serializeJsonPretty(root, Serial);
// This prints:
// {
// "sensor": "gps",

View File

@ -76,7 +76,7 @@ void loop() {
}
Serial.print(F("Sending: "));
root.printTo(Serial);
serializeJson(root, Serial);
Serial.println();
// Write response headers
@ -86,7 +86,7 @@ void loop() {
client.println();
// Write JSON document
root.prettyPrintTo(client);
serializeJsonPretty(root, client);
// Disconnect
client.stop();

View File

@ -72,11 +72,11 @@ void loop() {
Serial.print(remoteIp);
Serial.print(F(" on port "));
Serial.println(remotePort);
root.printTo(Serial);
serializeJson(root, Serial);
// Send UDP packet
udp.beginPacket(remoteIp, remotePort);
root.printTo(udp);
serializeJson(root, udp);
udp.println();
udp.endPacket();

View File

@ -54,7 +54,7 @@ void setup() {
// Lastly, you can print the resulting JSON to a String
String output;
root.printTo(output);
serializeJson(root, output);
}
void loop() {