Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- folly::dynamic json{
- folly::dynamic::object ("desc", folly::dynamic::object ("id", 10)("name","John"))("data", folly::dynamic::array (42,33,26))
- };
- std::string jsonStr{ folly::toJson (json) };
- std::cout << "JSON: " << jsonStr << '\n';
- folly::dynamic fromJson{ folly::parseJson (jsonStr) };
- auto dynData{ fromJson["data"] };
- int id{ fromJson["desc"]["id"].asInt () };
- std::string name{ fromJson["desc"]["name"].asString () };
- std::array<int, 3> data;
- auto dataIter{ data.begin () };
- //std::copy (dynData.begin (), dynData.end (), data.begin ());
- std::for_each (dynData.begin (), dynData.end (), [&dataIter] (folly::dynamic item) { *dataIter++ = item.asInt (); /*std::cout << item.asInt () << ' ';*/ });
- std::cout << '\n';
- std::cout << "ID: " << id << '\n';
- std::cout << "NAME: " << name << '\n';
- std::cout << "DATA: ";
- for (const auto val : data)
- {
- std::cout << val << ' ';
- }
- std::cout << '\n';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement