comparison include/core/json.h @ 323:1686fac290c5

services/anilist: refactor HTTP requests...
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 22:48:16 -0400
parents b1f4d1867ab1
children
comparison
equal deleted inserted replaced
322:c32467cd06bb 323:1686fac290c5
22 22
23 } // namespace nlohmann 23 } // namespace nlohmann
24 24
25 namespace JSON { 25 namespace JSON {
26 26
27 /* TODO: refactor these to return a std::optional... */
28 template<typename T = std::string> 27 template<typename T = std::string>
29 T GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def) { 28 T GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def) {
30 if (json.contains(ptr) && json[ptr].is_string()) 29 if (json.contains(ptr) && json[ptr].is_string())
31 return json[ptr].get<T>(); 30 return json[ptr].get<T>();
32 else 31 else