#pragma once #ifdef WIN32 #include #endif #include "cJSON.h" #include #include class json { cJSON *obj_; cJSON* cur_child_; cJSON* find_child(cJSON *parent, const char* child_name); cJSON* find(const char* path); public: json(char* json_txt = 0); ~json(); static std::string to_string(cJSON* root); static std::string get_value_as_string(cJSON* root, bool integer = false); public: bool attach_text(char* json_txt); bool attach_cjson(cJSON* cjson); void clear(void); std::string to_string(void); // can be path: child/value ... bool get_value(const char* key, bool& val); bool get_value(const char* key, int& val); bool get_value(const char* key, double& val); bool get_value(const char* key, std::string& val); bool get_value(const char* key, json*& val); // caller shoud call "delete" to free the returned object !!! bool get_value_as_string(const char* key, std::string& val, bool integer); bool get_as_array(const char* key, std::vector& val); bool first_child(std::string& val); bool next_child(std::string& val); bool set_value(const char* key, bool val); bool set_value(const char* key, int val); bool set_value(const char* key, double val); bool set_value(const char* key, std::string val); };