mirror of
https://github.com/kgabis/parson.git
synced 2025-02-05 17:05:29 +00:00
Adds json_object_get_value_at function to access values in objects in O(1) time.
Also adds some missing null checking.
This commit is contained in:
parent
77ef99571e
commit
473c7f3d8d
10
parson.c
10
parson.c
@ -983,14 +983,20 @@ size_t json_object_get_count(const JSON_Object *object) {
|
||||
}
|
||||
|
||||
const char * json_object_get_name(const JSON_Object *object, size_t index) {
|
||||
if (index >= json_object_get_count(object))
|
||||
if (object == NULL || index >= json_object_get_count(object))
|
||||
return NULL;
|
||||
return object->names[index];
|
||||
}
|
||||
|
||||
JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index) {
|
||||
if (object == NULL || index >= json_object_get_count(object))
|
||||
return NULL;
|
||||
return object->values[index];
|
||||
}
|
||||
|
||||
/* JSON Array API */
|
||||
JSON_Value * json_array_get_value(const JSON_Array *array, size_t index) {
|
||||
if (index >= json_array_get_count(array))
|
||||
if (array == NULL || index >= json_array_get_count(array))
|
||||
return NULL;
|
||||
return array->items[index];
|
||||
}
|
||||
|
1
parson.h
1
parson.h
@ -127,6 +127,7 @@ int json_object_dotget_boolean(const JSON_Object *object, const char *
|
||||
/* Functions to get available names */
|
||||
size_t json_object_get_count(const JSON_Object *object);
|
||||
const char * json_object_get_name (const JSON_Object *object, size_t index);
|
||||
JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index);
|
||||
|
||||
/* Creates new name-value pair or frees and replaces old value with a new one.
|
||||
* json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
|
||||
|
Loading…
Reference in New Issue
Block a user