items.cpp 514 B

1234567891011121314151617181920212223
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create JSON values
  7. json j_object = {{"one", 1}, {"two", 2}};
  8. json j_array = {1, 2, 4, 8, 16};
  9. // example for an object
  10. for (auto& x : j_object.items())
  11. {
  12. std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
  13. }
  14. // example for an array
  15. for (auto& x : j_array.items())
  16. {
  17. std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
  18. }
  19. }