An Embeddable NoSQL Database Engine |
Tweet |
Follow @unqlite_db |
UnQLite C/C++ API Reference - JSON Array/Object handling.
unqlite_value * unqlite_array_fetch(unqlite_value *pArray,const char *zKey,int nByte);
Extract record value from a JSON array/object.
Description
This routine is used to extract a record value from a JSON array or a field value from a JSON object where zKey is its key. The unqlite_value must be of type array or object obtained by a prior successful call to unqlite_vm_new_array(), unqlite_context_new_array() or passed as parameter to the foreign function.
If the target value is a JSON array (i.e. numerically indexed), you can pass numeric string keys such as “1”, “2”, “750”, etc. UnQLite is smart enough to figure out that we are dealing with numeric keys.
If the given key does not refer to a valid entry then NULL is returned. Otherwise the entry value is returned on success. This value can be manipulated or modified using one these interfaces and the change is immediately seen in the target JSON array/object:
Note: This routine is not thread-safe.
Parameters
pArray
|
unqlite_value to query which must be of type array or object. |
zKey
|
Lookup key. |
nByte
|
zkey length. If this argument is less than zero, then zKey is read up to the first zero terminator. If nByte is non-negative, then it is the maximum number of bytes read from zKey. |
Return value
If the given key does not refer to a valid array record, object field or the given unqlite_value is not of type array/object then NULL is returned. Otherwise the entry value is returned on success.
Example
Compile this C file for a smart introduction to the JSON array/object handling interfaces.
See also
unqlite_array_walk, unqlite_array_count, unqlite_array_add_elem.