|
@@ -801,6 +801,7 @@ int json_walk(const char *json_string, int json_string_length,
|
|
}
|
|
}
|
|
|
|
|
|
struct scan_array_info {
|
|
struct scan_array_info {
|
|
|
|
+ int found;
|
|
char path[JSON_MAX_PATH_LEN];
|
|
char path[JSON_MAX_PATH_LEN];
|
|
struct json_token *token;
|
|
struct json_token *token;
|
|
};
|
|
};
|
|
@@ -815,6 +816,7 @@ static void json_scanf_array_elem_cb(void *callback_data, const char *name,
|
|
|
|
|
|
if (strcmp(path, info->path) == 0) {
|
|
if (strcmp(path, info->path) == 0) {
|
|
*info->token = *token;
|
|
*info->token = *token;
|
|
|
|
+ info->found = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -824,10 +826,11 @@ int json_scanf_array_elem(const char *s, int len, const char *path, int idx,
|
|
struct json_token *token) {
|
|
struct json_token *token) {
|
|
struct scan_array_info info;
|
|
struct scan_array_info info;
|
|
info.token = token;
|
|
info.token = token;
|
|
|
|
+ info.found = 0;
|
|
memset(token, 0, sizeof(*token));
|
|
memset(token, 0, sizeof(*token));
|
|
snprintf(info.path, sizeof(info.path), "%s[%d]", path, idx);
|
|
snprintf(info.path, sizeof(info.path), "%s[%d]", path, idx);
|
|
json_walk(s, len, json_scanf_array_elem_cb, &info);
|
|
json_walk(s, len, json_scanf_array_elem_cb, &info);
|
|
- return token->len;
|
|
|
|
|
|
+ return info.found ? token->len : -1;
|
|
}
|
|
}
|
|
|
|
|
|
struct json_scanf_info {
|
|
struct json_scanf_info {
|