diff --git a/src/json-editor.c b/src/json-editor.c index 04c03665d75c7294a430e20959f5ce42cef69936..d8090496711b890807a8ee8b5c8a5598d5f6680c 100644 --- a/src/json-editor.c +++ b/src/json-editor.c @@ -482,6 +482,7 @@ struct json_object *json_object_get_by_string_delimiter(struct json_object *src, for (char *key = strtok(fmt_cpy,delimiter); key != NULL; key = strtok(NULL, delimiter)) { int len = 0; + len = get_idx(key, idx, parsed_key); json_object_object_get_ex(outer_obj, parsed_key, &ptr); @@ -490,6 +491,7 @@ struct json_object *json_object_get_by_string_delimiter(struct json_object *src, return NULL; int index = (idx[i] == -1 ? json_object_array_length(ptr) -1 : idx[i]); + ptr = json_object_array_get_idx(ptr, index); } @@ -507,11 +509,10 @@ int json_object_del_by_string(struct json_object *src, char *fmt) int json_object_del_by_string_delimiter(struct json_object *src, char *fmt, const char *delimiter) { - struct json_object *ptr, *outer_obj, *j_idx; + struct json_object *ptr, *outer_obj; char fmt_cpy[1024] = {0}, parsed_key[32] = {0}; char *p, *key = fmt; int idx[32]; - int len; if (!src) { fprintf(stderr, "%s error: No object\n", __func__); @@ -534,6 +535,7 @@ int json_object_del_by_string_delimiter(struct json_object *src, char *fmt, cons if (p) { int len = 0; + len = get_idx(key, idx, parsed_key); json_object_object_get_ex(outer_obj, parsed_key, &ptr); @@ -542,6 +544,7 @@ int json_object_del_by_string_delimiter(struct json_object *src, char *fmt, cons return -1; int index = (idx[i] == -1 ? json_object_array_length(ptr) -1 : idx[i]); + ptr = json_object_array_get_idx(ptr, index); }