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

Function first_example_a

examples/src/examples.cpp:18–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16using namespace jsoncons;
17
18void first_example_a()
19{
20 std::string path = "./input/books.json";
21 std::fstream is(path);
22 if (!is)
23 {
24 std::cout << "Cannot open " << path << '\n';
25 return;
26 }
27 json books = json::parse(is);
28
29 for (const auto& book : books.at("books").array_range())
30 {
31 try
32 {
33 std::string author = book["author"].as<std::string>();
34 std::string title = book["title"].as<std::string>();
35 double price = book["price"].as<double>();
36 std::cout << author << ", " << title << ", " << price << '\n';
37 }
38 catch (const std::exception& e)
39 {
40 std::cerr << e.what() << '\n';
41 }
42 }
43}
44
45void first_example_b()
46{

Callers 1

mainFunction · 0.85

Calls 3

parseFunction · 0.85
atMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected