Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <ArduinoSTL.h>
  3.  
  4. /*
  5.  * Correctly outputs
  6. Chave1
  7. Valor1
  8. {
  9. {\"
  10. {\"Chave1
  11. {\"Chave1\"
  12. {\"Chave1\":
  13. {\"Chave1\":\"
  14. {\"Chave1\":\"Valor1
  15. {\"Chave1\":\"Valor1\"
  16. Chave2
  17. Valor2
  18. {\"Chave1\":\"Valor1\",
  19. {\"Chave1\":\"Valor1\",\"
  20. {\"Chave1\":\"Valor1\",\"Chave2
  21. {\"Chave1\":\"Valor1\",\"Chave2\"
  22. {\"Chave1\":\"Valor1\",\"Chave2\":
  23. {\"Chave1\":\"Valor1\",\"Chave2\":\"
  24. {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2
  25. {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2\"
  26. {\"Chave1\":\"Valor1\",\"Chave2\":\"Valor2\"}
  27.  *
  28.  *
  29.  * */
  30.  
  31.  
  32. using namespace std;
  33.  
  34. String jsonificar(vector<vector<String>> sujeito) {
  35.     String json_txt = String(""), chave, valor;
  36.     String chave_str, valor_str;
  37.  
  38.     json_txt += String("{");
  39.     for (unsigned int i = 0; i < sujeito.size(); i++) {
  40.         if (sujeito[i].size() != 2) {
  41.             Serial.println("Cada conteudo deve conter 2 textos!");
  42.         } else {
  43.             chave = sujeito[i][0];
  44.             valor = sujeito[i][1];
  45.             Serial.println(chave);
  46.             Serial.println(valor);
  47.             Serial.println(json_txt);
  48.             json_txt += "\\\"";
  49.             Serial.println(json_txt);
  50.             json_txt += chave;
  51.             Serial.println(json_txt);
  52.             json_txt += "\\\"";
  53.             Serial.println(json_txt);
  54.             json_txt += ":";
  55.             Serial.println(json_txt);
  56.             json_txt += "\\\"";
  57.             Serial.println(json_txt);
  58.             json_txt += valor;
  59.             Serial.println(json_txt);
  60.             json_txt += "\\\"";
  61.             Serial.println(json_txt);
  62.  
  63.             if (i != sujeito.size() - 1) {
  64.                 json_txt += String(",");
  65.             }
  66.         }
  67.     }
  68.  
  69.     json_txt += "}";
  70.     Serial.println(json_txt);
  71.  
  72.     return json_txt;
  73. }
  74.  
  75. void setup(void) {
  76.     Serial.begin(115200);
  77. }
  78.  
  79. void loop(void) {
  80.  
  81.     vector<vector<String>> v = {
  82.             {"Chave1", "Valor1"},
  83.             {"Chave2", "Valor2"},
  84.     };
  85.  
  86.     jsonificar(v);
  87.     delay(1000);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement