| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #pragma once
- #include <map>
- #include <stdexcept>
- #include <string>
- namespace reginfo {
- // Minimal JSON object for flat string key/value pairs.
- // Supports only string values — sufficient for license data.
- class JsonObject {
- public:
- void set(const std::string& key, const std::string& value) { data_[key] = value; }
- std::string get(const std::string& key) const {
- auto it = data_.find(key);
- if (it == data_.end())
- throw std::runtime_error("Missing JSON key: " + key);
- return it->second;
- }
- std::string get(const std::string& key, const std::string& defaultValue) const {
- auto it = data_.find(key);
- return (it != data_.end()) ? it->second : defaultValue;
- }
- bool contains(const std::string& key) const {
- return data_.find(key) != data_.end();
- }
- // Parse from JSON string like {"key":"value",...}
- static JsonObject parse(const std::string& json);
- // Serialize to JSON string
- std::string dump(bool pretty = false) const;
- const std::map<std::string, std::string>& data() const { return data_; }
- private:
- std::map<std::string, std::string> data_;
- };
- } // namespace reginfo
|