Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <ArduinoSTL.h>
- /*
- * Correctly outputs
- Chave1
- Valor1
- {
- {\"
- {\"Chave1
- {\"Chave1\"
- {\"Chave1\":
- {\"Chave1\":\"
- {\"Chave1\":\"Valor1
- {\"Chave1\":\"Valor1\"
- Chave2
- Valor2
- {\"Chave1\":\"Valor1\",
- {\"Chave1\":\"Valor1\",\"
- {\"Chave1\":\"Valor1\",\"Chave2
- {\"Chave1\":\"Valor1\",\"Chave2\"
- {\"Chave1\":\"Valor1\",\"Chave2\":
- {\"Chave1\":\"Valor1\",\"Chave2\":\"
- {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2
- {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2\"
- {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2\"}
- *
- *
- * */
- using namespace std;
- 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;
- }
- void setup(void) {
- Serial.begin(115200);
- }
- void loop(void) {
- vector<vector<String>> v = {
- {"Chave1", "Valor1"},
- {"Chave2", "Valor2"},
- };
- jsonificar(v);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement