You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.5 KiB
73 lines
1.5 KiB
|
|
#ifndef _JSON_H_
|
|
#define _JSON_H_
|
|
|
|
#include <list>
|
|
#include <string>
|
|
#include <string.h>
|
|
|
|
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<JSONElement> *l);
|
|
void SetObject (string n, string s);
|
|
string GetString();
|
|
};
|
|
|
|
class JSONParse {
|
|
private:
|
|
string jsondata;
|
|
list<JSONElement> 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<JSONElement> 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_
|