MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / first_example_b

Function first_example_b

examples/src/examples.cpp:45–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void first_example_b()
46{
47 std::string path = "./input/books.json";
48 std::fstream is(path);
49 if (!is)
50 {
51 std::cout << "Cannot open " << path << '\n';
52 return;
53 }
54 json books = json::parse(is);
55
56 for (const auto& book : books.at("books").array_range())
57 {
58 try
59 {
60 std::string author = book["author"].as<std::string>();
61 std::string title = book["title"].as<std::string>();
62 std::string price = book.get_value_or<std::string>("price", "N/A");
63 std::cout << author << ", " << title << ", " << price << '\n';
64 }
65 catch (const std::exception& e)
66 {
67 std::cerr << e.what() << '\n';
68 }
69 }
70}
71
72void first_example_c()
73{

Callers 1

mainFunction · 0.85

Calls 3

parseFunction · 0.85
atMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected