I intend to create a function to jsify sensors' content and save it on a SD-card or send through a http client. Except for the Serial.println
's, the function is transcripted below.
String jsonificar(vector<vector<String>> sujeito){
String json_txt = String(""), chave, valor;
String chave_str, valor_str;
json_txt+=String("{");
for(unsigned int i = 0; i<sujeito.size(); i++){
if(sujeito[i].size() != 2){
Serial.println("Cada conteudo deve conter 2 textos!");
}
else{
chave = sujeito[i][0];
valor = sujeito[i][1];
Serial.println(chave);
Serial.println(valor);
Serial.println(json_txt);
json_txt += "\\\"";
Serial.println(json_txt);
json_txt += chave;
Serial.println(json_txt);
json_txt += "\\\"";
Serial.println(json_txt);
json_txt += ":";
Serial.println(json_txt);
json_txt += "\\\"";
Serial.println(json_txt);
json_txt += valor;
Serial.println(json_txt);
json_txt += "\\\"";
Serial.println(json_txt);
if(i != sujeito.size() - 1){
json_txt += String(",");
}
}
}
json_txt+="}";
Serial.println(json_txt);
return json_txt;
}
The output on serial follows:
Output:
Chave1
Valor1
{
{\"
{\"Chave1
{\"Chave1\"
{\"Chave1\":
{\"Chave1\":\"
{\"Chave1\":\"Valor1
{\"Chave1\":\"Valor1\"
Chave2
Valor2
{\"Chave1\":\"Valor1\",
{\"Chave1\":\"Valor1\",\"
{\"Chave1\":\"Valor1\",\" <===
{\"Chave1\":\"Valor1\",\"\"
{\"Chave1\":\"Valor1\",\"\": <===
{\"Chave1\":\"Valor1\",\"\": <===
{\"Chave1\":\"Valor1\",\"\": <===
{\"Chave1\":\"Valor1\",\"\": <===
{\"Chave1\":\"Valor1\",\"\":}
The arrows show the spots where the logs are different from expected: the keys and values provided are "Chave1", "Valor1", "Chave2", "Valor2". So, the key-value should be "Chave2":"Valor2". Would you have a grasp of this behaviour? I look forward for the answer!
std::vector
into Arduino? It doesn't compile for me.ArduinoSTL
. I also usePlatformIO
as IDE and it saysvector
comes fromnamespace std
.