Cant pass a quote

Hello guys,

client.print("{"id":");
 client.print("1770,");
 client.print(""measurement:"");
 client.print(distance);
 client.print("}");

I need to have an output as this

{"id":123,"measurement":10}

so i need some double "" and I am having some errors in the IDE. Is there anyway that I can define the next character as a character (whatever it is)?

Billy

You need to escape for certain characters. You use a backslash.

Serial.println("This \" will print a quote");

To expand on Delta_G's post

    Serial.begin(9600);
    Serial.print("{\"id\":");  // backslash before embedded quotes
    Serial.print("1770,");
    Serial.print("\"measurement\":");  // backslash before embedded quotes
    Serial.print(distance);
    Serial.print("}");

This shows how to format the escape char with quotes in your code.

Output:

{"id":1770,"measurement":0}

thank you mates :slight_smile:

You can use single quotes too. Javascript doesn't care.

client.print("{'id':");