If you insert a value (or a key) of type String, std::string, or const _FlashStringHelper*, ArduinoJson stores a copy in the JsonDocument.ĭon’t forget to take this into account when you compute the capacity of the JsonDocument. String duplication also happens when you populate a JsonDocument. In that case, the parser copies the strings to the JsonDocument. On the other hand, if the input is read-only ( const char*, String, or Stream), the parser assumes that the input is volatile. In that case, it stores pointers to the string in the input. If the input is mutable ( char* or char), the parser assumes that the input buffer is persistent. String duplication in ArduinoJsonĭepending on the type of input, the parser uses a different storage strategy for strings: The seven bytes correspond to the characters of the string "values", including the terminator. Suppose your JSON document is:Ĭonst size_t capacity = JSON_OBJECT_SIZE ( 1 ) + JSON_ARRAY_SIZE ( 3 ) + 7 When serializing, ArduinoJson copies all strings that are not const char* ( see below). When deserializing, ArduinoJson copies the strings from the input, except if the input is a char* ( see below). On top of that, you need to add the capacity required to store the strings that ArduinoJson needs to duplicate. JSON_ARRAY_SIZE(n) returns the size of a JSON array with n elements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |