xref: /third_party/json/docs/examples/operator_deserialize.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <iomanip>
3c5f01b2fSopenharmony_ci#include <sstream>
4c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ciusing json = nlohmann::json;
7c5f01b2fSopenharmony_ci
8c5f01b2fSopenharmony_ciint main()
9c5f01b2fSopenharmony_ci{
10c5f01b2fSopenharmony_ci    // create stream with serialized JSON
11c5f01b2fSopenharmony_ci    std::stringstream ss;
12c5f01b2fSopenharmony_ci    ss << R"({
13c5f01b2fSopenharmony_ci        "number": 23,
14c5f01b2fSopenharmony_ci        "string": "Hello, world!",
15c5f01b2fSopenharmony_ci        "array": [1, 2, 3, 4, 5],
16c5f01b2fSopenharmony_ci        "boolean": false,
17c5f01b2fSopenharmony_ci        "null": null
18c5f01b2fSopenharmony_ci    })";
19c5f01b2fSopenharmony_ci
20c5f01b2fSopenharmony_ci    // create JSON value and read the serialization from the stream
21c5f01b2fSopenharmony_ci    json j;
22c5f01b2fSopenharmony_ci    ss >> j;
23c5f01b2fSopenharmony_ci
24c5f01b2fSopenharmony_ci    // serialize JSON
25c5f01b2fSopenharmony_ci    std::cout << std::setw(2) << j << '\n';
26c5f01b2fSopenharmony_ci}
27

Indexes created Thu Nov 07 10:32:03 CST 2024