text
stringlengths 0
14.1k
|
---|
if (!dict_getter(dict, key, strlen(key), &val, JSON_STRING, true)) |
return false; |
return json_value_as_string(val, dst_p, len_p); |
} |
bool json_dict_get_list(struct JsonValue *dict, const char *key, struct JsonValue **dst_p) |
{ |
return dict_getter(dict, key, strlen(key), dst_p, JSON_LIST, true); |
} |
bool json_dict_get_dict(struct JsonValue *dict, const char *key, struct JsonValue **dst_p) |
{ |
return dict_getter(dict, key, strlen(key), dst_p, JSON_DICT, true); |
} |
/* |
* Load optional dict element. |
*/ |
bool json_dict_get_opt_bool(struct JsonValue *dict, const char *key, bool *dst_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_BOOL, false)) |
return false; |
return !val || json_value_as_bool(val, dst_p); |
} |
bool json_dict_get_opt_int(struct JsonValue *dict, const char *key, int64_t *dst_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_INT, false)) |
return false; |
return !val || json_value_as_int(val, dst_p); |
} |
bool json_dict_get_opt_float(struct JsonValue *dict, const char *key, double *dst_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_FLOAT, false)) |
return false; |
return !val || json_value_as_float(val, dst_p); |
} |
bool json_dict_get_opt_string(struct JsonValue *dict, const char *key, const char **dst_p, size_t *len_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_STRING, false)) |
return false; |
return !val || json_value_as_string(val, dst_p, len_p); |
} |
bool json_dict_get_opt_list(struct JsonValue *dict, const char *key, struct JsonValue **dst_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_LIST, false)) |
return false; |
if (val) |
*dst_p = val; |
return true; |
} |
bool json_dict_get_opt_dict(struct JsonValue *dict, const char *key, struct JsonValue **dst_p) |
{ |
struct JsonValue *val; |
if (!dict_getter(dict, key, strlen(key), &val, JSON_DICT, false)) |
return false; |
if (val) |
*dst_p = val; |
return true; |
} |
/* |
* Load value from list. |
*/ |
bool json_list_get_value(struct JsonValue *list, size_t index, struct JsonValue **val_p) |
{ |
struct JsonValue *val; |
struct ValueList *vlist; |
size_t i; |
vlist = get_list_vlist(list); |
if (!vlist) |
return false; |
if (index >= list->u.v_size) |
return false; |
if (!vlist->array && list->u.v_size > 10) |
prepare_array(list); |
/* direct fetch */ |
if (vlist->array) { |