Go to the documentation of this file.
28 #ifndef CPL_JSON_H_INCLUDED
29 #define CPL_JSON_H_INCLUDED
31 #include "cpl_progress.h"
43 typedef void *JSONObjectH;
92 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
97 void Add(
const std::string &osName,
const std::string &osValue);
98 void Add(
const std::string &osName,
const char *pszValue);
99 void Add(
const std::string &osName,
double dfValue);
100 void Add(
const std::string &osName,
int nValue);
101 void Add(
const std::string &osName,
GInt64 nValue);
102 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
103 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
104 void Add(
const std::string &osName,
bool bValue);
105 void AddNull(
const std::string &osName);
107 void Set(
const std::string &osName,
const std::string &osValue);
108 void Set(
const std::string &osName,
const char *pszValue);
109 void Set(
const std::string &osName,
double dfValue);
110 void Set(
const std::string &osName,
int nValue);
111 void Set(
const std::string &osName,
GInt64 nValue);
112 void Set(
const std::string &osName,
bool bValue);
113 void SetNull(
const std::string &osName);
116 JSONObjectH GetInternalHandle()
const {
return m_poJsonObject; }
120 std::string GetString(
const std::string &osName,
const std::string &osDefault =
"")
const;
121 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
122 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
123 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
124 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
125 std::string ToString(
const std::string &osDefault =
"")
const;
126 double ToDouble(
double dfDefault = 0.0)
const;
127 int ToInteger(
int nDefault = 0)
const;
129 bool ToBool(
bool bDefault =
false)
const;
131 std::string Format(
enum PrettyFormat eFormat)
const;
134 void Delete(
const std::string &osName);
138 enum Type GetType()
const;
140 std::string GetName()
const {
return m_osKey; }
143 std::vector<CPLJSONObject> GetChildren()
const;
144 bool IsValid()
const;
149 CPLJSONObject GetObjectByPath(
const std::string &osPath, std::string &osName)
const;
153 JSONObjectH m_poJsonObject =
nullptr;
154 std::string m_osKey{};
171 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
176 void Add(
const std::string &osValue);
177 void Add(
const char* pszValue);
178 void Add(
double dfValue);
179 void Add(
int nValue);
181 void Add(
bool bValue);
199 bool Save(
const std::string &osPath)
const;
200 std::string SaveAsString()
const;
204 bool Load(
const std::string &osPath);
205 bool LoadMemory(
const std::string &osStr);
206 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
207 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
208 GDALProgressFunc pfnProgress =
nullptr,
209 void *pProgressArg =
nullptr);
210 bool LoadUrl(
const std::string &osUrl,
char **papszOptions,
211 GDALProgressFunc pfnProgress =
nullptr,
212 void *pProgressArg =
nullptr);
215 mutable JSONObjectH m_poRootJsonObject;
220 #endif // CPL_JSON_H_INCLUDED
The JSONArray class JSON array from JSONDocument.
Definition: cpl_json.h:161
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
@ Plain
No extra whitespace or formatting applied.
Definition: cpl_json.h:77
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:267
@ Spaced
Minimal whitespace inserted.
Definition: cpl_json.h:78
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:337
PrettyFormat
Json object format to string options.
Definition: cpl_json.h:76
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:54
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:339
Type
Json object types.
Definition: cpl_json.h:61
void Add(const std::string &osName, const std::string &osValue)
Add new key - value pair to json object.
Definition: cpl_json.cpp:457
CPLJSONObject operator[](const std::string &osName) const
Get value by key.
Definition: cpl_json.cpp:814
The CPLJSONDocument class Wrapper class around json-c library.
Definition: cpl_json.h:190