|
@@ -16,7 +16,7 @@ JSON parser and generator for C/C++
|
|
1. Copy `frozen.c` and `frozen.h` to your project
|
|
1. Copy `frozen.c` and `frozen.h` to your project
|
|
2. Add `frozen.c` to the list of source files
|
|
2. Add `frozen.c` to the list of source files
|
|
3. Parsing with Frozen is done in two steps: first, split JSON string
|
|
3. Parsing with Frozen is done in two steps: first, split JSON string
|
|
- into tokens by `parse_json()`, `parse_json2()` or `parse_json_file()`.
|
|
|
|
|
|
+ into tokens by `parse_json()` or `parse_json2()`.
|
|
Second, search for certain
|
|
Second, search for certain
|
|
parameters in parsed string by `find_json_token()`. Below is an example,
|
|
parameters in parsed string by `find_json_token()`. Below is an example,
|
|
error handling is omitted for clarity:
|
|
error handling is omitted for clarity:
|
|
@@ -47,11 +47,10 @@ JSON parser and generator for C/C++
|
|
int parse_json(const char *json_string, int json_string_length,
|
|
int parse_json(const char *json_string, int json_string_length,
|
|
struct json_token *tokens_array, int size_of_tokens_array);
|
|
struct json_token *tokens_array, int size_of_tokens_array);
|
|
struct json_token *parse_json2(const char *json_string, int string_length);
|
|
struct json_token *parse_json2(const char *json_string, int string_length);
|
|
- struct json_token *parse_json_file(const char *path);
|
|
|
|
|
|
|
|
-`parse_json()` and `parse_json2()` parse a string, `parse_json_file()` parses
|
|
|
|
-file. `parse_json()` needs pre-allocated tokens array or NULL, whereas
|
|
|
|
-`parse_json2()` and `parse_json_file()` allocate tokens array automatically.
|
|
|
|
|
|
+`parse_json()` and `parse_json2()` parse JSON string.
|
|
|
|
+`parse_json()` needs pre-allocated tokens array or NULL, whereas
|
|
|
|
+`parse_json2()` allocates tokens array automatically.
|
|
|
|
|
|
|
|
|
|
`parse_json()` tokenizes `json_string` of length `json_string_length`.
|
|
`parse_json()` tokenizes `json_string` of length `json_string_length`.
|
|
@@ -89,8 +88,7 @@ returned, one of:
|
|
#define JSON_STRING_INCOMPLETE -2
|
|
#define JSON_STRING_INCOMPLETE -2
|
|
#define JSON_TOKEN_ARRAY_TOO_SMALL -3
|
|
#define JSON_TOKEN_ARRAY_TOO_SMALL -3
|
|
|
|
|
|
-`parse_json2()` and `parse_json_file()` return NULL on error
|
|
|
|
-and non-NULL on success.
|
|
|
|
|
|
+`parse_json2()` returns NULL on error and non-NULL on success.
|
|
|
|
|
|
Below is an illustration on how JSON string gets tokenized:
|
|
Below is an illustration on how JSON string gets tokenized:
|
|
|
|
|