///////////////////////////////////////////////////////////////////////////////// // // json.h is part of TestModbus-Server. // ///////////////////////////////////////////////////////////////////////////////// #ifndef _JSON_H_ #define _JSON_H_ #include #include #include using namespace std; enum { JSON_T_NONE, JSON_T_STRING, JSON_T_NUMBER, JSON_T_OBJECT, JSON_T_ARRAY }; class JSONElement { public: int type; string name; string value; JSONElement() { Clear(); }; ~JSONElement() {}; void Clear() { type = JSON_T_NONE; name = ""; value = ""; }; void Set (string n, double v); void Set (string n, int v); void Set (string n, int64_t v); void Set (string n, string v); void SetArray (string n, list *l); void SetObject (string n, string s); string GetString(); }; class JSONParse { private: string jsondata; list names; public: JSONParse() { Set("{}"); }; JSONParse(string json) { Set(json); }; ~JSONParse() {}; void Clear(); int Set(string json); int GetValue(string varname, string *dest); int GetValueInt(string varname, int *dest); int GetValueInt64(string varname, int64_t *dest); int GetObject(string varname, JSONParse *dest); int GetIdx(string src, int idx, string *dest); int GetValueIdx(string varname, int idx, string *dest); int GetObjectIdx(string varname, int idx, JSONParse *dest); list GetElements(); void AddObject (JSONElement element); void AddObject (string name, int val); void AddObject (string name, int64_t val); void AddObject (string name, string val); void AddObject (string name, double val); void AddObject (string name, JSONParse jp); string ToString(); }; #endif // _JSON_H_