Closed
Description
I was able to directly pass File to a parseObject and it was read properly, but when i added the struct, the way you suggest it to be added in another thread, it wont accept the File any more.
This was working ok:
DynamicJsonBuffer configFileJB;
File configFile = SPIFFS.open("/settings.json", "r");
if (!configFile) {
Serial.println("Failed to open config file");
}
JsonObject& settings = configFileJB.parseObject(configFile);
Now when i added the struct:
struct JsonBundle {
public:
void parse(const char* json) {
_jsonBuffer = new DynamicJsonBuffer();
_jsonVariant = _jsonBuffer->parseObject(json);
}
const JsonObject& root() const {
return _jsonVariant;
}
const JsonObject& getNode(String key) const {
JsonObject& i = _jsonVariant.as<JsonObject>().get<JsonVariant>(key);
return i;
}
private:
DynamicJsonBuffer* _jsonBuffer;
JsonVariant _jsonVariant;
};
JsonBundle settings;
I can't pass File to .parse() i have to do this:
DynamicJsonBuffer configFileJB;
File configFile = SPIFFS.open("/settings.json", "r");
size_t size = configFile.size();
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
settings.parse(buf.get());
How is the File recognizes in first example? Can't figure out from here: https://arduinojson.org/api/jsonbuffer/parseobject/