Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "json.hpp"
- int main() {
- JSONObject * jsonObject = new JSONObject();
- jsonObject->add("name", new JSONString("John Doe"));
- jsonObject->add("age", new JSONNumber(25));
- jsonObject->add("isStudent", new JSONBoolean(true));
- JSONArray * jsonArray = new JSONArray();
- jsonArray->add(new JSONString("apple"));
- jsonArray->add(new JSONString("banana"));
- jsonArray->add(new JSONString("orange"));
- jsonObject->add("fruits", jsonArray);
- // Convertendo para string JSON
- std::string jsonString = jsonObject->toString();
- std::cout << "JSON String: " << jsonString << std::endl;
- // Liberando a memória alocada
- delete (*jsonObject)["name"];
- delete (*jsonObject)["age"];
- delete (*jsonObject)["isStudent"];
- delete (*jsonObject)["fruits"];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement