Home --> Documentations --> PJLIB-UTIL Reference
|
void | pj_json_elem_null (pj_json_elem *el, pj_str_t *name) |
|
void | pj_json_elem_bool (pj_json_elem *el, pj_str_t *name, pj_bool_t val) |
|
void | pj_json_elem_number (pj_json_elem *el, pj_str_t *name, float val) |
|
void | pj_json_elem_string (pj_json_elem *el, pj_str_t *name, pj_str_t *val) |
|
void | pj_json_elem_array (pj_json_elem *el, pj_str_t *name) |
|
void | pj_json_elem_obj (pj_json_elem *el, pj_str_t *name) |
|
void | pj_json_elem_add (pj_json_elem *el, pj_json_elem *child) |
|
pj_json_elem * | pj_json_parse (pj_pool_t *pool, char *buffer, unsigned *size, pj_json_err_info *err_info) |
|
pj_status_t | pj_json_write (const pj_json_elem *elem, char *buffer, unsigned *size) |
|
pj_status_t | pj_json_writef (const pj_json_elem *elem, pj_json_writer writer, void *user_data) |
|
This API implements JSON file format according to RFC 4627. It can be used to parse, write, and manipulate JSON documents.
◆ pj_json_writer
typedef pj_status_t(* pj_json_writer) (const char *s, unsigned size, void *user_data) |
Type of function callback to write JSON document in pj_json_writef().
- Parameters
-
s | The string to be written to the document. |
size | The length of the string |
user_data | User data that was specified to pj_json_writef() |
- Returns
- If the callback returns non-PJ_SUCCESS, it will stop the pj_json_writef() function and this error will be returned to caller.
◆ pj_json_val_type
Type of JSON value.
Enumerator |
---|
PJ_JSON_VAL_NULL | Null value (null)
|
PJ_JSON_VAL_BOOL | Boolean value (true, false)
|
PJ_JSON_VAL_NUMBER | Numeric (float or fixed point)
|
PJ_JSON_VAL_STRING | Literal string value.
|
PJ_JSON_VAL_ARRAY | Array
|
PJ_JSON_VAL_OBJ | Object.
|
◆ pj_json_elem_add()
Add an element to an object or array.
- Parameters
-
el | The object or array element. |
child | Element to be added to the object or array. |
◆ pj_json_elem_array()
Initialize element as an empty array
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
◆ pj_json_elem_bool()
Initialize boolean element with the specified value.
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
val | The value. |
◆ pj_json_elem_null()
Initialize null element.
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
◆ pj_json_elem_number()
Initialize number element with the specified value.
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
val | The value. |
◆ pj_json_elem_obj()
Initialize element as an empty object
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
◆ pj_json_elem_string()
Initialize string element with the specified value.
- Parameters
-
el | The element. |
name | Name to be given to the element, or NULL. |
val | The value. |
◆ pj_json_parse()
Parse a JSON document in the buffer. The buffer MUST be NULL terminated, or if not then it must have enough size to put the NULL character.
- Parameters
-
pool | The pool to allocate memory for creating elements. |
buffer | String buffer containing JSON document. |
size | Size of the document. |
err_info | Optional structure to be filled with info when parsing failed. |
- Returns
- The root element from the document.
◆ pj_json_write()
Write the specified element to the string buffer.
- Parameters
-
elem | The element to be written. |
buffer | Output buffer. |
size | On input, it must be set to the size of the buffer. Upon successful return, this will be set to the length of the written string. |
- Returns
- PJ_SUCCESS on success or the appropriate error.
◆ pj_json_writef()
Incrementally write the element to arbitrary medium using the specified callback to write the document chunks.
- Parameters
-
elem | The element to be written. |
writer | Callback function which will be called to write text chunks. |
user_data | Arbitrary user data which will be given back when calling the callback. |
- Returns
- PJ_SUCCESS on success or the appropriate error.
References PJ_END_DECL.
PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.
|