From 5f0fce4191309e9526b7109a0d87c092ce6a4193 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Thu, 18 Feb 2021 14:14:23 +0100 Subject: main --- json/jsonparse.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 json/jsonparse.c (limited to 'json/jsonparse.c') diff --git a/json/jsonparse.c b/json/jsonparse.c new file mode 100644 index 0000000..6cfae2e --- /dev/null +++ b/json/jsonparse.c @@ -0,0 +1,167 @@ +#include +#include +#include +#include + +#include + +void substr_token (char *json, char *temp, jsmntok_t *t) { + memcpy(temp, json+t->start, t->end - t->start); + temp[t->end-t->start] = '\0'; +} + +void json_parse_array(char *json, void *temp, jsmntok_t *t, int r, char type) { + for (int i=0; i pair set with a set of already parsed tokens +int json_parse_dict_ci_init (char *json, + pair_ci *dict, jsmntok_t *t, int r) { + int obj_i = 0, dict_i = -1; + for (int i=0; i pair set with a set of already parsed tokens +int json_parse_dict_cf_init (char *json, + pair_cf *dict, jsmntok_t *t, int r) { + int obj_i = 0, dict_i = -1; + for (int i=0; i pair set +int json_parse_dict_ci (char *json, pair_ci *dict) { + jsmn_parser p; jsmn_init(&p); + jsmntok_t t[MAXTOKENS]; + int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); + json_parse_dict_ci_init(json, dict, t, r); +} + +// parses a pair set +int json_parse_dict_cf (char *json, pair_cf *dict) { + jsmn_parser p; jsmn_init(&p); + jsmntok_t t[MAXTOKENS]; + int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); + json_parse_dict_cf_init(json, dict, t, r); +} + + + +// parses a list of objects which are lists of pairs +int json_parse_list_ci (char *json, list_ci *list) { + jsmn_parser p; jsmn_init(&p); + jsmntok_t t[MAXTOKENS]; + int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); + int list_i = 0; + for (int i=1; i +int json_parse_list_cf (char *json, list_cf *list) { + jsmn_parser p; jsmn_init(&p); + jsmntok_t t[MAXTOKENS]; + int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); + int list_i = 0; + for (int i=1; i