libjson 编译和使用 - 3. libjson的C接口 API

继续上一篇libjson 编译和使用 - 2. 配置使用lib文件

这里我不想写太多,主要内容从libjson的document那里而来,在这里mark一下方便以后查找,这里先吧英文版的贴出来改天再翻译一下


C interface
libjson has an interface that uses standard C types and a standard C interface. This interface
doesn’t have to be used in just C, it can be used in Basic, C, C++ and any other language that supports
the C interface (most do.) All methods in libjson begin.

JSONNODE types
function
description
JSON_NULL
Blank node or "null" (case-less)
JSON_STRING
A string
JSON_NUMBER
A floating point number
JSON_BOOL
A boolean "true" or "false" (case-less)
JSON_ARRAY
An array of JSONNodes
JSON_NODE
A complex JSONNode structure
libjson types
function
description
JSONNODE *
Opaque pointer to a node within libjson
JSONNODE_ITERATOR
Random access iterator
JSONSTREAM
Opaque pointer to a stream
json_char
Either char or wchar_t, depending on options
json_number
Either float or double, depending on options
json_index_t
Child node indexing type
json_bool_t
Boolean type
json_int_t
Int type
json_error_callback_t
typedef void (* json_error_callback_t)(const json_char *)
json_stream_callback_t
typedef void (* json_stream_callback_t)(JSONNODE *, void *)
json_stream_e_callback_t
typedef void (* json_stream_e_callback_t)(void *)
json_mutex_callback_t
typedef void (* json_mutex_callback_t)(void *)
json_malloc_t
typedef void * (* json_malloc_t)(unsigned long)
json_realloc_t
typedef void * (* json_realloc_t)(void *, unsigned long)
json_free_t
typedef void (* json_free_t)(void *)
JSONNODE functions
function
description
json_new
Construct JSONNode
json_new_a
Constructs a string node
json_new_i
Constructs a integer node
json_new_f
Constructs a floating point node
json_new_b
Constructs a boolean node
json_copy
Copy JSONNode content, usually reference counting
json_duplicate
Copy JSONNode content, forcing a copy
json_delete
Deletes the node
json_delete_all
Deletes all allocated nodes
Inspector functions
function
description
json_type
The type of JSONNode it is
json_size
The number of child nodes
json_empty
Tests if the node has children
json_name
The name of the node
json_get_comment
The comment attached to the node
json_as_string
The string value of the node
json_as_int
The integer value of the string
json_as_float
The floating point value of the string
json_as_bool
The boolean value of the string
json_as_node
The node, cast to a JSON_NODE
json_as_array
The node, cast to a JSON_ARRAY
json_as_binary
The node with it's value converted to binary
json_write
Writes the node as JSON text
json_write_formatted
Writes the node as readable JSON text
json_equal
Compare JSONNode contents
Modifier Functions
function
description
json_set_a
Sets the contents of the node to a string
json_set_i
Sets the contents of the node to an int
json_set_f
Sets the contents of the node to a float
json_set_b
Sets the contents of the node to a bool
json_set_n
Sets the contents of the node to another node
json_set_name
Sets the name of the node
json_set_comment
Sets the comment attached to the node
json_clear
Removes all children
json_nullify
Nulls out the node
json_swap
Swap the contents of two nodes
json_merge
Merges the contents of two or more nodes
json_preparse
Completely parses the JSON
json_set_binary
Sets the binary value of the node
json_cast
Change the node's type
Streaming Functions
function
description
json_new_stream
Creates a stream
json_stream_push
Pushes data onto the stream
json_delete_stream
Deletes the stream
Children Access Functions
function
description
json_at
Access item by index
json_get
Access item by name or index
json_get_nocase
Assess item by name, case-insensitive
json_reserve
Reserve enough space
json_push_back
Adds a child
json_pop_back_at
Removes and returns an item by index
json_pop_back
Removes and returns an item by name
json_pop_back_nocase
Removes and returns an item by name, case-insensitive
json_find
Finds a node by name
json_find_nocase
Finds a node by name, case-insensitive
json_erase
Removes an item
json_erase_multi
Remove a set of children
json_insert
Adds a child
json_insert_multi
Insert a set of children
Iterator Functions
function
description
json_begin
Return iterator to beginning
json_end
Return iterator to end
Thread Safety Functions
function
description
json_lock
Return iterator to end
json_unlock
Return reverse iterator to reverse beginning
json_set_mutex
Attaches a mutex to the node
json_set_global_mutex
Sets the global mutex
JSON Functions
function
description
json_parse
Parses json
json_parse_unformatted
Parses son that has no white spaces
json_strip_white_space
Removes all white space and comment
json_is_valid
Validates json
json_is_valid_unformatted
Validates json that has no white spaces
json_validate
(deprecated) Validates json and if it's valid, return an object
Callback Registration
function
description
json_register_debug_callback
Registers error callback
json_register_mutex_callbacks
Register mutex callbacks
json_register_memory_callbacks
Registers the memory callbacks
Cleanup Functions
function
description
json_free
Frees memory of a string
json_free_all
Frees memory of all strings that libjson had allocated
Base64 Functions
function
description
json_encode64
Base64 encodes data
json_decode64
Decodes Base64 data
Text Functions
function
description
JSON_TEXT
Creates a text string in the right format


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页