aJSONObject* item = aJson.createObject()

Hello,

Thank you all for your help on these Forums.

I am running the below code:

#include <aJSON.h>
int i = 0

void setup(){
Serial.Begin(9600);
}

void loop(){

int A = 3;
int B = 4;
int C = 5;
int D = i;
aJsonObject* data = aJson.createObject();
aJson.addNumberToObject(data, “temp”,B);
aJson.addNumberToObject(data, “pres”,A);
aJson.addNumberToObject(data, “turb”,C);
aJson.addNumberToObject(data, “count”,D);
String json = aJson.print(data);
//char* json = aJson.print(data);
aJson.deleteItem(data);
Serial.println(“Here is my JSON Object”);
Serial.println(json);

i += 1;
delay(50);
}

I the use the json string for a HTTP Post request. (not shown)

While Monitoring the Serial Output:

After 238 loops the object stops being created and disappears. The serial continues to print but there is nothing in the aJsonObject*.

I use the count variable to monitor how many prints/creates i get and it stops at 238.
It stops at 246 when I make json a char* type instead of type String. The output is below.
I thought the object create allocates the memory and delete Item reallocates the memory when finished. Am I running out of memory?

string type

Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:235}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:236}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:237}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:238}
Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

char* type

Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:242}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:243}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:244}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:245}
Here is my JSON Object
{“temp”:4.00000,“pres”:3.00000,“turb”:5.00000,“count”:246}
Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Here is my JSON Object

Looks like some sort of memory leak in either the json library or String itself.

You get empty strings when String tries to allocate memory and can't find any memory; pretty sure that's what's happening.

String is notorious for causing weird memory problems, and I suspect that json library is probably doing the same sort of things.

Why not just write the json to a char array using sprintf()?

Hello DrAzzy,

Not really sure how to do that. LOL.

Thanks

I got it now bud.

Thanks