| 70 | } |
| 71 | |
| 72 | void 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 | |
| 112 | void first_example_d() |
| 113 | { |