Serializes the JsonArray
to create a prettified JSON document.
If you want a compact JSON without space or line break, use JsonArray::printTo()
size_t prettyPrintTo(char* buffer, size_t size) const;
size_t prettyPrintTo(char buffer[size]) const;
size_t prettyPrintTo(Print &) const;
size_t prettyPrintTo(String &) const;
size_t prettyPrintTo(std::string &) const;
Arguments
The destination where the JSON document should be written. It can be either:
buffer
with specified size
(the size includes the null terminator),Print
(like Serial
, EthernetClient
…),String
or std::string
.This function treats String
and std::string
as streams: it doesn’t replace the content, it appends to the end.
The number of bytes written.
How to view the JSON output?When you pass a Stream
to JsonArray::prettyPrintTo()
, it writes the JSON document to the stream but doesn’t print anything to the serial port, which makes troubleshooting difficult.
If you want to see what JsonArray::prettyPrintTo()
writes, use WriteLoggingStream
from the StreamUtils library.
When you pass a Stream
to JsonArray::prettyPrintTo()
, it sends the bytes one by one, which can be slow depending on the target stream. For example, if you send to a WiFiClient
on an ESP8266, it will send a packet over the air for each byte, which is terribly slow and inefficient. To improve speed and efficiency, we must send fewer, larger packets.
To write the JSON document in chunks, you can use WriteBufferingStream
from the StreamUtils library.
StaticJsonBuffer<200> jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
array.add("hello");
array.add("world");
array.prettyPrintTo(Serial);
will write the following string to the serial output:
See alsoJsonArray::printTo()
JsonArray::measurePrettyLength()
JsonObject::prettyPrintTo()
JsonVariant::prettyPrintTo()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4