Error class Xxx
has no member named read
This error occurs when you pass an invalid input type to deserializeJson()
or deserializeMsgPack()
.
For example, if you write this:
class Input {
// ...
};
void parseInput(Input input) {
JsonDocument doc;
deserializeJson(doc, input);
// ...
}
You’ll get a long compiler output that includes this error:
ArduinoJson/Deserialization/Reader.hpp:21:21: error: 'class Input' has no member named 'read'
return source_->read(); // Error here? See https://arduinojson.org/v7/invalid-input/
First, you should double-check that you called deserializeJson()
with the right arguments.
The second argument should be one of the supported input types:
If you do want to read from an unsupported input type (like Input
in the example above), you must implement read()
and readBytes()
like this:
class Input {
// Reads one byte or returns -1
int read();
// Reads several bytes and returns the number of bytes read.
size_t readBytes(char* buffer, size_t length);
};
If you cannot modify the Input
class, you can write an adapter class that implements read()
and readBytes()
and forwards the calls to the Input
class. The book Mastering ArduinoJson shows how to do that for FILE*
.
See also
- Custom reader
- ArduinoJson 6.13.0: custom reader and writer
- Chapter “Advanced Techniques” in the book Mastering ArduinoJson