51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#if defined(WIN32) || defined(_WIN64)
|
|
#include <Windows.h>
|
|
#endif
|
|
|
|
#include "cJSON.h"
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
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 ...
|
|
std::string key(void);
|
|
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<std::string>& 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);
|
|
|
|
};
|