Closed sukhmeet032795 closed 8 years ago
I'll assume you're running on an ESP8866.
The DynamicJsonBuffer
release the memory as soon as it's out of scope, so whar you're doing is good.
Since you know the that the JSON is big, you should specify an initial capacity to the constructor. the default is 256B, you can easily push it to 4064.
But I can see that you're loosing a lot of memory by duplicating the strings.
Instead of this:
int size = responceCheckout.length() + 1;
char responceCheckoutJson[size];
responceCheckout.toCharArray(responceCheckoutJson, size);
DynamicJsonBuffer json;
JsonObject &data = json.parseObject(responceCheckoutJson);
You should do this:
DynamicJsonBuffer json(4096);
JsonObject &data = json.parseObject(const_cast<char*>(responceCheckout.c_str()));
But I'm not sure, this is the reason of the crash...
Can you please locate the line of the exception more precisely?
Can you please check how much memory is available when those function starts?
Can you please print the jsonBuffer.size()
after the parse?
Also, have a look at #168, #179, #184, #119 and FAQ
Thanks for a quick reply.
I tried what you suggested, the size comes out to be 1204....and i looking out for the exception line......meanwhile thanks a ton
Btw is DynamicJsonBuffer json(4096) taking the same memory everytime i re-declare it or takes a new memory?
If you do this:
{
DynamicJsonBuffer buffer1(4096);
// [...]
}
{
DynamicJsonBuffer buffer2(4096);
// [...]
}
Then it's very likely that buffer1
and buffer2
will use the exact same 4096 bytes of heap.
However, if you do this:
{
DynamicJsonBuffer buffer1(4096);
// [...]
DynamicJsonBuffer buffer2(4096);
// [...]
}
then in this case buffer1
and buffer2
will be in memory at the same time and therefore use 8192 bytes of heap.
Hey.was out of town
Thanks for all the help..appreciate it a lot
dynamicjsonbuffer does not have a name type
Hi,
I have two urls i.e /upload and /checkout. On making an api call to /upload, i get a json which is similar to the one shown below. This json is stored using Dynamic Json Buffer. On basis of this , at success i make another api call to /checkout and i get another json which i again store using DynamicJsonBuffer. My Code is:
The length of the json is not fixed, it may vary depending on the number of products int the basket. I was using DynamicJsonBuffer for storing the json but it causes exceptions
My code is:
On success it calls sendCheckoutRequest, which is:
Now when i store another json, i get exceptions as:
How can i resolve this? Is it possible to store the jsons in same static memory by erasing other one from memory? How can i use StaticJsonBuffer to accomplish this job successfully..
Need urgent help.Thanks in advance.