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

Function first_example_c

examples/src/examples.cpp:72–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72void first_example_c()
73{
74 const json books = json::parse(R"(
75 [
76 {
77 "title" : "Kafka on the Shore",
78 "author" : "Haruki Murakami",
79 "price" : 25.17
80 },
81 {
82 "title" : "Women: A Novel",
83 "author" : "Charles Bukowski",
84 "price" : 12.00
85 },
86 {
87 "title" : "Cutter's Way",
88 "author" : "Ivan Passer"
89 }
90 ]
91 )");
92
93 auto options = json_options{};
94
95 for (const auto& book : books.array_range())
96 {
97 try
98 {
99 std::string author = book["author"].as<std::string>();
100 std::string title = book["title"].as<std::string>();
101 std::string price;
102 book.get_value_or<json>("price", "N/A").dump(price,options);
103 std::cout << author << ", " << title << ", " << price << '\n';
104 }
105 catch (const ser_error& e)
106 {
107 std::cerr << e.what() << '\n';
108 }
109 }
110}
111
112void first_example_d()
113{

Callers 1

mainFunction · 0.85

Calls 3

parseFunction · 0.85
dumpMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected