annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "json.h"
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 namespace JSON {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 std::string GetString(nlohmann::json const& json, std::string const& key) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 auto item = json.find(key);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 if (item != json.end() && item->is_string())
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 return item->get<std::string>();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 else return "";
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 int GetInt(nlohmann::json const& json, std::string const& key) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 auto item = json.find(key);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 if (item != json.end() && item->is_number())
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 return item->get<int>();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 else return 0;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 bool GetBoolean(nlohmann::json const& json, std::string const& key) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 auto item = json.find(key);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 if (item != json.end() && item->is_boolean())
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 return item->get<bool>();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 else return false;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 double GetDouble(nlohmann::json const& json, std::string const& key) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 auto item = json.find(key);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 if (item != json.end() && item->is_number())
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 return item->get<double>();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 else return 0;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34