comparison src/json.cpp @ 2:23d0d9319a00

Update Also converted everything to LF from CRLF
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 03:16:26 -0400
parents
children 1d82f6e04d7d
comparison
equal deleted inserted replaced
1:1ae666fdf9e2 2:23d0d9319a00
1 #include "json.h"
2
3 namespace JSON {
4
5 std::string GetString(nlohmann::json const& json, std::string const& key) {
6 auto item = json.find(key);
7 if (item != json.end() && item->is_string())
8 return item->get<std::string>();
9 else return "";
10 }
11
12 int GetInt(nlohmann::json const& json, std::string const& key) {
13 auto item = json.find(key);
14 if (item != json.end() && item->is_number())
15 return item->get<int>();
16 else return 0;
17 }
18
19 bool GetBoolean(nlohmann::json const& json, std::string const& key) {
20 auto item = json.find(key);
21 if (item != json.end() && item->is_boolean())
22 return item->get<bool>();
23 else return false;
24 }
25
26 double GetDouble(nlohmann::json const& json, std::string const& key) {
27 auto item = json.find(key);
28 if (item != json.end() && item->is_number())
29 return item->get<double>();
30 else return 0;
31 }
32
33 }
34