Skip to content

QUESTION: Getting "null"s in return from fucntion returning DynamicJsonDocument #1084

Closed
@garbled1

Description

@garbled1

ESP8266:

My code, simplified: some of the silliness like doc=json_doc; is my attempt to debug.

DynamicJsonDocument read_gnhast_config()
{
DynamicJsonDocument doc(50);
if (thing) {
DynamicJsonDocument json_doc(size);

    Serial.println("opened config file");
    configFile.readBytes(buf.get(), size);
    DeserializationError j_error =
	deserializeJson(json_doc, buf.get());
    if (!j_error) {
	serializeJson(json_doc, Serial);
	Serial.println("\nparsed json");
	doc = json_doc;
	return doc;
         }
 }
 Serial.printf("wrong");
 return(doc); /* which in theory should be a null json doc */

}

void other_function()
{
DynamicJsonDocument gncfg(5000);

gncfg = read_gnhast_config();
serializeJson(gncfg, Serial);

}

When I run this, I get the following on the Serial terminal:

reading gnhast config file
opened config file
{"device":{"28E768270500005E":{"name":"Test DS1820B"}}}
parsed json
{"device":{null:null}}

So it correctly reads the file. It parses the json, and sees the full document, but when it passes it on, it passes it as null:null.

What confuses me here, is that it does pass "device".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions