![]() |
PIP 5.5.3
Platform-Independent Primitives
|
JSON class. More...
#include <pijson.h>
Public Types | |
| enum | Type { Invalid , Null , Boolean , Number , String , Object , Array } |
| Type of JSON tree element. More... | |
| enum | PrintType { Compact , Tree } |
| Generate JSON variant. More... | |
Public Member Functions | |
| PIJSON () | |
| Contructs invalid PIJSON. | |
| const PIString & | name () const |
| Returns name of element, or empty string if it doesn`t have name. | |
| const PIVector< PIJSON > & | array () const |
| Returns elements array of this element, or empty array if element is not PIJSON::Array. | |
| const PIMap< PIString, PIJSON > & | object () const |
| Returns elements map of this element, or empty map if element is not PIJSON::Object. | |
| const PIVariant & | value () const |
| Returns element value. | |
| bool | toBool () const |
| Returns element value as bool. | |
| int | toInt () const |
| Returns element value as integer number. | |
| double | toDouble () const |
| Returns element value as floating-point number. | |
| PIString | toString () const |
| Returns element value as string, valid for all types. | |
| Type | type () const |
| Returns element type. | |
| bool | isValid () const |
| Returns if element is valid. | |
| bool | isObject () const |
| Returns if element is PIJSON::Object. | |
| bool | isArray () const |
| Returns if element is PIJSON::Array. | |
| void | setValue (const PIVariant &v) |
| Set value and type of element from "v". More... | |
| void | clear () |
| Clear element and set it to PIJSON::Invalid. | |
| int | size () const |
| Returns size of elements array if type is PIJSON::Array, size of elements map if type is PIJSON::Object, otherwise returns 0. | |
| bool | contains (const PIString &key) const |
| Returns if elements map contains key "key" if type is PIJSON::Object, otherwise returns false. | |
| void | resize (int new_size) |
| Set element type to PIJSON::Array and resize elements array to "new_size". | |
| PIJSON & | operator= (const PIVariant &v) |
| Synonim of setValue(). | |
| const PIJSON & | operator[] (int index) const |
| Returns element from array with index "index" if type is PIJSON::Array, otherwise returns invalid PIJSON. | |
| PIJSON & | operator[] (int index) |
| Set element type to PIJSON::Array, resize if necessary and returns element from array with index "index". | |
| PIJSON & | operator<< (const PIJSON &element) |
| Set element type to PIJSON::Array and add element to the end of array. | |
| PIJSON & | operator<< (const PIVariant &value) |
| Set element type to PIJSON::Array and add element to the end of array. | |
| PIJSON | operator[] (const PIString &key) const |
| Returns element from map with key "key" if type is PIJSON::Object, otherwise returns invalid PIJSON. | |
| PIJSON & | operator[] (const PIString &key) |
| Set element type to PIJSON::Object and returns element from map with key "key". If element with this key doesn`t exists, it will be created. | |
| PIString | toJSON (PrintType print_type=Compact, bool mask_unicode=true) const |
| Returns text representation of JSON tree. | |
Static Public Member Functions | |
| static PIJSON | fromJSON (PIString str) |
| Parse text representation of JSON "str" and returns it root element. | |
JSON class.
Разбор:
Создание:
Простой массив
Массив объектов
| enum PIJSON::Type |
| enum PIJSON::PrintType |
| void PIJSON::setValue | ( | const PIVariant & | v | ) |
Set value and type of element from "v".
If "v" type is boolean set type to PIJSON::Boolean.
If "v" type is any numeric set type to PIJSON::Number.
If "v" type is string set type to PIJSON::String.
In case of any other type set element type to PIJSON::Invalid.