Hi!
I'm trying to create a String in the json format like this:
String json = {"91234": {"status": "NotOk"}};
where "91234" is a string variable.
So it would be:
String STRING_VARIABLE = "91234";
String json = {STRING_VARIABLE: {"status": "NotOk"}};
but I am not able to concatenate that into a variable.
can anybody help me?
J-M-L
March 20, 2021, 4:32pm
2
we would probably not recommend the String class if you can do otherwise but with a String that could look like this
String STRING_VARIABLE = "91234";
String json = "{\"" + STRING_VARIABLE + "\": {\"status\": \"NotOk\"}}";
void setup() {
Serial.begin(115200);
Serial.println(STRING_VARIABLE);
Serial.println(json);
}
void loop() {}
Serial Monitor (@ 115200 bauds) will show
[color=purple]
91234
{"91234": {"status": "NotOk"}}
[/color]
note that you can't directly have double quotes in a string, you need to 'escape' it (see escape sequences ) that's why you can see " appearing the the String definition where double quotes are needed
1 Like
system
Closed
July 18, 2021, 4:40pm
5
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.