-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QUESTION: Getting "null"s in return from fucntion returning DynamicJsonDocument #1084
Comments
Oh, quick note. Using 6.11.5 |
Hi @garbled1, The See: Best Regards, |
Oh... I totally misunderstood https://arduinojson.org/v6/api/dynamicjsondocument/ I'll try this out tonight, I'm sure my problem will magically go away. :) Thank you! |
I think something else is going on here... I tried setting the allocations of all of my DynamicJsonDocument's to 2048. My actual data is: Now my code does this: opened config file The second print of the line is in the function that called the read from file function. So again, it reads it from disk, parses it correctly, and then when I return the value, it's corrupt. Now it's just corrupt differently... Can I not return a DynamicJsonDocument from a function? Do I have to do something else to do so? My code now looks like this: DynamicJsonDocument read_gnhast_config()
} int create_devices(int nrofdevs)
} |
I think my fault.. adding a configFile.close() made all the problems go away. Some kind of memory corruption I guess? Odd... |
@garbled1 , PS with doc = doc2; and doc isn't big enough, it will indeed auto-resize doc based on the size of doc2 (at least that's my understanding after looking at the code). However, if some storage container for doc or doc2 goes out of scope, the data will get corrupted (sooner or later). |
@ewaldc is right,
As Ewald said, you can fix this issue by passing the file directly to See also: |
I think this makes more sense to me now. I'm used to doing C on Unix, so things like this come as a surprise to me. Makes alot of sense in a low memory environment. Just.. Caught me off guard. However, learning that I can just straight up give it the filehandle, that's gold. So much easier. Seems to work fine now switching it over to the file handle, and it's less code. |
You're welcome @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);
}
void other_function()
{
DynamicJsonDocument gncfg(5000);
}
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".
The text was updated successfully, but these errors were encountered: