OGR
Public Types | Public Member Functions | Friends | List of all members
CPLJSONObject Class Reference

The CPLJSONArray class holds JSON object from CPLJSONDocument. More...

#include <cpl_json.h>

Inheritance diagram for CPLJSONObject:
CPLJSONArray

Public Types

enum  Type
 
enum  PrettyFormat { Plain, Spaced, Pretty }
 

Public Member Functions

void Add (const std::string &osName, const std::string &osValue)
 
void Add (const std::string &osName, const char *pszValue)
 
void Add (const std::string &osName, double dfValue)
 
void Add (const std::string &osName, int nValue)
 
void Add (const std::string &osName, GInt64 nValue)
 
void Add (const std::string &osName, const CPLJSONArray &oValue)
 
void Add (const std::string &osName, const CPLJSONObject &oValue)
 
void Add (const std::string &osName, bool bValue)
 
void AddNull (const std::string &osName)
 
void Set (const std::string &osName, const std::string &osValue)
 
void Set (const std::string &osName, const char *pszValue)
 
void Set (const std::string &osName, double dfValue)
 
void Set (const std::string &osName, int nValue)
 
void Set (const std::string &osName, GInt64 nValue)
 
void Set (const std::string &osName, bool bValue)
 
void SetNull (const std::string &osName)
 
std::string GetString (const std::string &osName, const std::string &osDefault="") const
 
double GetDouble (const std::string &osName, double dfDefault=0.0) const
 
int GetInteger (const std::string &osName, int nDefault=0) const
 
GInt64 GetLong (const std::string &osName, GInt64 nDefault=0) const
 
bool GetBool (const std::string &osName, bool bDefault=false) const
 
std::string ToString (const std::string &osDefault="") const
 
double ToDouble (double dfDefault=0.0) const
 
int ToInteger (int nDefault=0) const
 
GInt64 ToLong (GInt64 nDefault=0) const
 
bool ToBool (bool bDefault=false) const
 
CPLJSONArray ToArray () const
 
std::string Format (enum PrettyFormat eFormat) const
 
void Delete (const std::string &osName)
 
CPLJSONArray GetArray (const std::string &osName) const
 
CPLJSONObject GetObj (const std::string &osName) const
 
CPLJSONObject operator[] (const std::string &osName) const
 
enum Type GetType () const
 
std::vector< CPLJSONObjectGetChildren () const
 Get json object children. More...
 
bool IsValid () const
 
void Deinit ()
 

Friends

class CPLJSONArray
 
class CPLJSONDocument
 

Detailed Description

The CPLJSONArray class holds JSON object from CPLJSONDocument.

Member Enumeration Documentation

◆ PrettyFormat

Json object format to string options

Enumerator
Plain 

No extra whitespace or formatting applied.

Spaced 

Minimal whitespace inserted.

Pretty 

Formatted output.

◆ Type

Json object types

Member Function Documentation

◆ Add() [1/8]

void CPLJSONObject::Add ( const std::string &  osName,
const std::string &  osValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
osValueString value.
Since
GDAL 2.3

References IsValid().

Referenced by Set().

◆ Add() [2/8]

void CPLJSONObject::Add ( const std::string &  osName,
const char *  pszValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
pszValueString value.
Since
GDAL 2.3

References IsValid().

◆ Add() [3/8]

void CPLJSONObject::Add ( const std::string &  osName,
double  dfValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
dfValueDouble value.
Since
GDAL 2.3

References IsValid().

◆ Add() [4/8]

void CPLJSONObject::Add ( const std::string &  osName,
int  nValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
nValueInteger value.
Since
GDAL 2.3

References IsValid().

◆ Add() [5/8]

void CPLJSONObject::Add ( const std::string &  osName,
GInt64  nValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
nValueLong value.
Since
GDAL 2.3

References IsValid().

◆ Add() [6/8]

void CPLJSONObject::Add ( const std::string &  osName,
const CPLJSONArray oValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
oValueArray value.
Since
GDAL 2.3

References IsValid().

◆ Add() [7/8]

void CPLJSONObject::Add ( const std::string &  osName,
const CPLJSONObject oValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
oValueJson object value.
Since
GDAL 2.3

References IsValid().

◆ Add() [8/8]

void CPLJSONObject::Add ( const std::string &  osName,
bool  bValue 
)

Add new key - value pair to json object.

Parameters
osNameKey name.
bValueBoolean value.
Since
GDAL 2.3

References IsValid().

◆ AddNull()

void CPLJSONObject::AddNull ( const std::string &  osName)

Add new key - null pair to json object.

Parameters
osNameKey name.
Since
GDAL 2.3

References IsValid().

Referenced by SetNull().

◆ Deinit()

void CPLJSONObject::Deinit ( )

Decrement reference counter and make pointer NULL. A json object will become invalid.

Since
GDAL 2.3

◆ Delete()

void CPLJSONObject::Delete ( const std::string &  osName)

Delete json object by key.

Parameters
osNameKey name.
Since
GDAL 2.3

References IsValid().

Referenced by Set(), and SetNull().

◆ Format()

std::string CPLJSONObject::Format ( enum PrettyFormat  eFormat) const

Stringify object to json format.

Parameters
eFormatFormat type,
Returns
A string in JSON format.
Since
GDAL 2.3

References Pretty, and Spaced.

◆ GetArray()

CPLJSONArray CPLJSONObject::GetArray ( const std::string &  osName) const

Get value by key.

Parameters
osNameKey name.
Returns
Json array object.
Since
GDAL 2.3

References IsValid().

◆ GetBool()

bool CPLJSONObject::GetBool ( const std::string &  osName,
bool  bDefault = false 
) const

Get value by key.

Parameters
osNameKey name.
bDefaultDefault value.
Returns
Boolean value.
Since
GDAL 2.3

References GetObj().

◆ GetChildren()

std::vector< CPLJSONObject > CPLJSONObject::GetChildren ( ) const

Get json object children.

This function is useful when keys is not know and need to iterate over json object items and get keys and values.

Returns
Array of CPLJSONObject class instance.
Since
GDAL 2.3

◆ GetDouble()

double CPLJSONObject::GetDouble ( const std::string &  osName,
double  dfDefault = 0.0 
) const

Get value by key.

Parameters
osNameKey name.
dfDefaultDefault value.
Returns
Double value.
Since
GDAL 2.3

References GetObj().

◆ GetInteger()

int CPLJSONObject::GetInteger ( const std::string &  osName,
int  nDefault = 0 
) const

Get value by key.

Parameters
osNameKey name.
nDefaultDefault value.
Returns
Integer value.
Since
GDAL 2.3

References GetObj().

◆ GetLong()

GInt64 CPLJSONObject::GetLong ( const std::string &  osName,
GInt64  nDefault = 0 
) const

Get value by key.

Parameters
osNameKey name.
nDefaultDefault value.
Returns
Long value.
Since
GDAL 2.3

References GetObj().

◆ GetObj()

CPLJSONObject CPLJSONObject::GetObj ( const std::string &  osName) const

Get value by key.

Parameters
osNameKey name.
Returns
Json object.
Since
GDAL 2.3

References IsValid().

Referenced by GetBool(), GetDouble(), GetInteger(), GetLong(), GetString(), and operator[]().

◆ GetString()

std::string CPLJSONObject::GetString ( const std::string &  osName,
const std::string &  osDefault = "" 
) const

Get value by key.

Parameters
osNameKey name.
osDefaultDefault value.
Returns
String value.
Since
GDAL 2.3

References GetObj().

◆ GetType()

CPLJSONObject::Type CPLJSONObject::GetType ( ) const

Get json object type.

Returns
Json object type.
Since
GDAL 2.3

◆ IsValid()

bool CPLJSONObject::IsValid ( ) const

Check if json object valid.

Returns
true if json object valid.
Since
GDAL 2.3

Referenced by Add(), AddNull(), OGRGeometryFactory::createFromGeoJson(), Delete(), GetArray(), and GetObj().

◆ operator[]()

CPLJSONObject CPLJSONObject::operator[] ( const std::string &  osName) const

Get value by key.

Parameters
osNameKey name.
Returns
Json object.
Since
GDAL 2.3

References GetObj().

◆ Set() [1/6]

void CPLJSONObject::Set ( const std::string &  osName,
const std::string &  osValue 
)

Change value by key.

Parameters
osNameKey name.
osValueString value.
Since
GDAL 2.3

References Add(), and Delete().

◆ Set() [2/6]

void CPLJSONObject::Set ( const std::string &  osName,
const char *  pszValue 
)

Change value by key.

Parameters
osNameKey name.
pszValueString value.
Since
GDAL 2.3

References Add(), and Delete().

◆ Set() [3/6]

void CPLJSONObject::Set ( const std::string &  osName,
double  dfValue 
)

Change value by key.

Parameters
osNameKey name.
dfValueDouble value.
Since
GDAL 2.3

References Add(), and Delete().

◆ Set() [4/6]

void CPLJSONObject::Set ( const std::string &  osName,
int  nValue 
)

Change value by key.

Parameters
osNameKey name.
nValueInteger value.
Since
GDAL 2.3

References Add(), and Delete().

◆ Set() [5/6]

void CPLJSONObject::Set ( const std::string &  osName,
GInt64  nValue 
)

Change value by key.

Parameters
osNameKey name.
nValueLong value.
Since
GDAL 2.3

References Add(), and Delete().

◆ Set() [6/6]

void CPLJSONObject::Set ( const std::string &  osName,
bool  bValue 
)

Change value by key.

Parameters
osNameKey name.
bValueBoolean value.
Since
GDAL 2.3

References Add(), and Delete().

◆ SetNull()

void CPLJSONObject::SetNull ( const std::string &  osName)

Change value by key.

Parameters
osNameKey name.
Since
GDAL 2.3

References AddNull(), and Delete().

◆ ToArray()

CPLJSONArray CPLJSONObject::ToArray ( ) const

Get value.

Returns
Array
Since
GDAL 2.3

◆ ToBool()

bool CPLJSONObject::ToBool ( bool  bDefault = false) const

Get value.

Parameters
bDefaultDefault value.
Returns
Boolean value.
Since
GDAL 2.3

◆ ToDouble()

double CPLJSONObject::ToDouble ( double  dfDefault = 0.0) const

Get value

Parameters
dfDefaultDefault value.
Returns
Double value.
Since
GDAL 2.3

◆ ToInteger()

int CPLJSONObject::ToInteger ( int  nDefault = 0) const

Get value.

Parameters
nDefaultDefault value.
Returns
Integer value.
Since
GDAL 2.3

◆ ToLong()

GInt64 CPLJSONObject::ToLong ( GInt64  nDefault = 0) const

Get value.

Parameters
nDefaultDefault value.
Returns
Long value.
Since
GDAL 2.3

◆ ToString()

std::string CPLJSONObject::ToString ( const std::string &  osDefault = "") const

Get value.

Parameters
osDefaultDefault value.
Returns
String value.
Since
GDAL 2.3

The documentation for this class was generated from the following files:

Generated for GDAL by doxygen 1.8.14.