Delete , after last value

Hi,

I have a sketch for sending some values over the internet by using a Ethershield.
only i have a (i think) little problem but i can not see the solution.

I have the next script:

  if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) 
  {
    digitalWrite(6,HIGH);                                         // Flash LED on recieve ON
    wiretx=*(Sensor*) rf12_data;                                 // Get the payload
      Serial.print(str.buf); 
    // JSON creation: JSON sent are of the format: {key1:value1,key2:value2} and so on
    str.reset();                                                  // Reset json string      
    str.print("{");                                    // RF recieved so no failure
    for(int i=0;i<16; i++)
    {
      if (wiretx.address[i][0] || wiretx.address[i][1])
      { 
        str.print("%22temp_");
        for (uint8_t p = 0; p < 2; p++)
        {
          str.print(wiretx.address[i][p],HEX);
            } 
            str.print("%22");
      str.print(':');
                  str.print("%22");
      str.print(wiretx.value[i]/100.0);
                  str.print("%22");
      str.print(",");
      }
    }

But when the last value is used from the buffer i want that i not use a , so the string is closed with a value and a "} and not with a ",}
How can i do that?
I like to hear it.
Regards,
DJ

Does it make a difference that you have single quotes here

str.print(':');

and double quotes here?

str.print(",");

Tools + Auto Format would fix your random indenting, and make your code much easier to read.

It looks like you are outputting a number of values, followed by a comma, in a loop, and you’d like to un-put the last comma. You can’t do that.

What you can do is decide whether to output the comma, or not.

Before the statement to output the comma, add if(i<15). This will cause the comma to be output after the first values, but not after the 16th value.

@CrossRoads
There is functional not really a different (I think :wink: ), but I’m testing at this moment the script to delete the last , so I have split some parts.
When the script is working I put everything together.

@PaulS,
First thanks for the tip to use the auto format function.
For about the if(i<15) is it possible that the value is count then the buffer it empty?
Because i have not always 16 values.

Because i have not always 16 values.

In that case, what you need to do is write out a value.
Then, if there is another value to output, output a comma and the value.

if(i > 0)
// output a comma
// ouptut a value