|
Simple JSON for C
|
Simple JSON for C. More...
#include <stddef.h>Go to the source code of this file.
Typedefs | |
| typedef struct s_json | s_json_t |
Enumerations | |
| enum | s_json_err_t { S_JSON_OK = 0, S_JSON_NOT_FOUND, S_JSON_ERR_NO_MEM, S_JSON_ERR_PARSE, S_JSON_ERR_WRONG_JSON, S_JSON_ERR_WRONG_ROOT, S_JSON_ERR_INTERNAL } |
Functions | |
| s_json_t * | s_json_init (const char *json_string, size_t json_string_len, s_json_err_t *rc) |
| int | s_json_int (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| long | s_json_long (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| double | s_json_double (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| float | s_json_float (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| int | s_json_boolean (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| char * | s_json_string (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| void | s_json_string_raw (const char **string_raw, size_t *string_raw_length, s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| int | s_json_object (s_json_t *json, const char *json_path, int root_object_index, s_json_err_t *rc) |
| void | s_json_cleanup (s_json_t *json) |
Simple JSON for C.
| typedef struct s_json s_json_t |
Opaque JSON document object.
| enum s_json_err_t |
A Simple JSON error.
| int s_json_boolean | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
Parse true/false to (int)1/(int)0 See s_json_int()
| void s_json_cleanup | ( | s_json_t * | json | ) |
Cleanup the memory resources associated with the given opaque s_json_t object.
| double s_json_double | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| float s_json_float | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| s_json_t* s_json_init | ( | const char * | json_string, |
| size_t | json_string_len, | ||
| s_json_err_t * | rc | ||
| ) |
Parse the json_string and return an opaque s_json_t object you later use to access json values. You should call s_json_cleanup() when you finish using the object.
| [in] | json_string | The json string to parse. It is not copied to new memory, so it has to exist at least as long as the s_json_t object exists. |
| [in] | json_string_len | The length of the json string. |
| [out] | rc | Used for error handling. Can be NULL. See s_json_err_t for a list of possible errors. |
| int s_json_int | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
| [in] | json | A valid/initialized s_json_t object. |
| [in] | json_path | The path of |
| [in] | root_object_index | Set this to 0 if you wan't to search the whole document. If you wan't to search just part of it (inside an object or array) then use the s_json_object() function to get the index of the object/array to search inside of. |
| [out] | rc | Used for error handling. Can be NULL. See s_json_err_t for a list of possible errors. |
| long s_json_long | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| int s_json_object | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| char* s_json_string | ( | s_json_t * | json, |
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| void s_json_string_raw | ( | const char ** | string_raw, |
| size_t * | string_raw_length, | ||
| s_json_t * | json, | ||
| const char * | json_path, | ||
| int | root_object_index, | ||
| s_json_err_t * | rc | ||
| ) |
See s_json_int()
| [out] | string_raw | NON '\0' terminated string!!! You have to use the string_raw_length parameter to find the end of the string. The string is not malloc()-ed as it still uses the original json_string you passed into the s_json_init() function for the backing memory storage. So it is only valid as long as json_string is valid!!! Do not free() it.!!! |
| [out] | string_raw_length | The length of the returned NON '\0' terminated string. |
When an error happens the string_raw pointer is set to NULL and the string_raw_length is set to 0 and rc (if you didn't pass NULL to it) contains the specific error code.
1.8.15