clear json array

Hey guys I am using json arduino library in one of my projects. I am sending some data in json format and it is OK. but when I send another data, it contains some previous data and after two or three times, the data eliminates from the json format. Although I am clearing json array with the following ocde, but I donot know why is it late, or am I missing something. Or is it something related to json object that I am sending.

DynamicJsonBuffer jbuffer;
JsonArray& Results = jbuffer.createArray();
JsonObject& finalObject = jbuffer.createObject();

for (int i = 0 ; i < Results.size() ; i++) {
Results.remove(i);
}

I appreciate your suggestions.

Regards,

Please post a complete program illustrating the problem

if (Serial2.read() != 0x7E)
{
return;
}
for (int i = 0; i < 6; i++)
{
//Serial.write(Serial2.read());
Rx_buffer = Serial2.read();

  • }*
  • if (Rx_buffer[5] != 0x7F)*
  • {*
  • return;*
  • }*
  • for (int i = 0; i < 4; i++)*
  • {*
    device = Rx_buffer*;
    _ }
    if (device[3] == 0x64)
    {_
    device[3] = Rx_buffer[4];
    _ }_
    uint16_t deviceAddress = (device[0] << 8) + device[1];
    _ Serial.println(String(deviceAddress, HEX));
    JsonObject& temp = jbuffer.createObject();
    //String my = “”;
    //my = my + String(deviceAddress, HEX);
    //temp [“card”] = my;
    temp [“card”] = String(deviceAddress, HEX);
    temp [“tx”] = String(device[2], HEX);
    temp [“rssi”] = String(device[3], HEX);
    //temp.prettyPrintTo(Serial);
    /my = “”;
    my = my + String(device[2], HEX);

    * temp [“tx”] = my;
    my = “”;
    my = my + String(device[3], HEX);
    temp [“rssi”] = my;
    my = “”;/

    * bool isMatch = false;
    for (int i = 0 ; i < Results.size() ; i++) {
    JsonObject& myObject = Results.get<JsonObject&>(i);
    if ((temp.get(“card”)).equalsIgnoreCase(myObject.get(“card”))) {
    isMatch = true;
    break;
    }
    }
    if (!isMatch) {
    Results.add(temp);
    //getBatteryStatus() ;
    }
    deviceCounter++;
    if (deviceCounter == 25)
    {_
    data_flag = true;
    _ deviceCounter = 0;
    temp.remove(“card”);
    temp.remove(“tx”);
    temp.remove(“rssi”);
    }
    In main, I am doing this.
    if (data_flag == true)
    {
    JsonObject& finalObject = jbuffer.createObject();_
    finalObject [“Time”] = “13.55”;//get_time_from_the_server();
    finalObject [“g_c”] = “GC09”;//Gateway_ID;
    finalObject [“apiKey”] = “test123”;//api_key;
    _ finalObject [“cards”] = Results;_
    finalObject [“Batt”] = “90”;//get_battery_status() ;
    _ finalObject.prettyPrintTo(Serial);
    // finalObject.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));_
    // server_call();
    _ delay(10);
    for (int i = 0 ; i < Results.size() ; i++) { //for clearing/emptying the json array, to get new time every time*
    * Results.remove(i);
    }
    finalObject.remove(“Time”);_
    finalObject.remove(“g_c”);
    _ finalObject.remove(“apiKey”);
    finalObject.remove(“cards”);
    finalObject.remove(“BAtt”);_
    data_flag = false;
    _ }*
    But this is showing some previous values. So I think I am not clearing json array or objects or buffer.
    Kindly give suggestions.
    Regards,_

You did not use code tags when posting your code so some of it has turned into italics and there is a smiley in it

Why don't people review their posts and why don't they read this before posting a programming question ?