Poco::JSON

class Object

Library: JSON
Package: JSON
Header: Poco/JSON/Object.h

Description

Represents a JSON object.

Member Summary

Member Functions: get, getArray, getNames, getObject, getValue, has, isArray, isNull, isObject, optValue, remove, set, size, stringify

Types

Ptr

typedef SharedPtr < Object > Ptr;

Constructors

Object

Object();

Default constructor

Object

Object(
    const Object & copy
);

Copy constructor

Destructor

~Object virtual

virtual ~Object();

Destructor

Member Functions

get

Dynamic::Var get(
    const std::string & key
) const;

Retrieves a property. An empty value is returned when the property doesn't exist.

getArray

Array::Ptr getArray(
    const std::string & key
) const;

Returns a SharedPtr to an array when the property is an array. An empty SharedPtr is returned when the element doesn't exist or is not an array.

getNames

void getNames(
    std::vector < std::string > & names
) const;

Returns all property names

getObject

Object::Ptr getObject(
    const std::string & key
) const;

Returns a SharedPtr to an object when the property is an object. An empty SharedPtr is returned when the property doesn't exist or is not an object

getValue inline

template < typename T > T getValue(
    const std::string & key
) const;

Retrieves the property with the given name and will try to convert the value to the given template type. The convert<T> method of Dynamic is called which can also throw exceptions for invalid values. Note: This will not work for an array or an object.

has inline

bool has(
    const std::string & key
) const;

Returns true when the given property exists

isArray inline

bool isArray(
    const std::string & key
) const;

Returns true when the given property contains an array

isNull inline

bool isNull(
    const std::string & key
) const;

Returns true when the given property contains a null value

isObject inline

bool isObject(
    const std::string & key
) const;

Returns true when the given property contains an object

optValue inline

template < typename T > T optValue(
    const std::string & key,
    const T & def
) const;

Returns the value of a property when the property exists and can be converted to the given type. Otherwise def will be returned.

remove inline

void remove(
    const std::string & key
);

Removes the property with the given key

set inline

void set(
    const std::string & key,
    const Dynamic::Var & value
);

Sets a new value

size inline

unsigned int size() const;

Returns the number of properties

stringify

void stringify(
    std::ostream & out,
    unsigned int indent = 0
) const;

Prints the object to out. When indent is 0, the object will be printed on one line without indentation.