Mercurial > minori
view src/json.cpp @ 4:5af270662505
Set override functions as override
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 12 Aug 2023 12:08:16 -0400 |
parents | 23d0d9319a00 |
children | 1d82f6e04d7d |
line wrap: on
line source
#include "json.h" namespace JSON { std::string GetString(nlohmann::json const& json, std::string const& key) { auto item = json.find(key); if (item != json.end() && item->is_string()) return item->get<std::string>(); else return ""; } int GetInt(nlohmann::json const& json, std::string const& key) { auto item = json.find(key); if (item != json.end() && item->is_number()) return item->get<int>(); else return 0; } bool GetBoolean(nlohmann::json const& json, std::string const& key) { auto item = json.find(key); if (item != json.end() && item->is_boolean()) return item->get<bool>(); else return false; } double GetDouble(nlohmann::json const& json, std::string const& key) { auto item = json.find(key); if (item != json.end() && item->is_number()) return item->get<double>(); else return 0; } }