Advertisement
klebermo

Untitled

Jun 2nd, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include "json.hpp"
  4.  
  5. int main() {
  6.     JSONObject * jsonObject = new JSONObject();
  7.  
  8.     jsonObject->add("name", new JSONString("John Doe"));
  9.     jsonObject->add("age", new JSONNumber(25));
  10.     jsonObject->add("isStudent", new JSONBoolean(true));
  11.  
  12.     JSONArray * jsonArray = new JSONArray();
  13.  
  14.     jsonArray->add(new JSONString("apple"));
  15.     jsonArray->add(new JSONString("banana"));
  16.     jsonArray->add(new JSONString("orange"));
  17.  
  18.     jsonObject->add("fruits", jsonArray);
  19.  
  20.     // Convertendo para string JSON
  21.     std::string jsonString = jsonObject->toString();
  22.     std::cout << "JSON String: " << jsonString << std::endl;
  23.  
  24.     // Liberando a memória alocada
  25.     delete (*jsonObject)["name"];
  26.     delete (*jsonObject)["age"];
  27.     delete (*jsonObject)["isStudent"];
  28.     delete (*jsonObject)["fruits"];
  29.  
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement