提交 287737f4 编写于 作者: D Dmitry Guryanov 提交者: Eric Blake

util: add functions for interating over json object

Add function virJSONValueObjectKeysNumber, virJSONValueObjectGetKey
and virJSONValueObjectGetValue, which allow you to iterate over all
fields of json object: you can get number of fields and then get
name and value, stored in field with that name by index.
Signed-off-by: NDmitry Guryanov <dguryanov@parallels.com>
上级 0d631e91
...@@ -235,6 +235,7 @@ Patches have also been contributed by: ...@@ -235,6 +235,7 @@ Patches have also been contributed by:
Ryan Woodsmall <rwoodsmall@gmail.com> Ryan Woodsmall <rwoodsmall@gmail.com>
Wido den Hollander <wido@widodh.nl> Wido den Hollander <wido@widodh.nl>
Eugen Feller <eugen.feller@inria.fr> Eugen Feller <eugen.feller@inria.fr>
Dmitry Guryanov <dguryanov@parallels.com>
[....send patches to get your name here....] [....send patches to get your name here....]
......
...@@ -671,14 +671,17 @@ virJSONValueObjectAppendNumberUlong; ...@@ -671,14 +671,17 @@ virJSONValueObjectAppendNumberUlong;
virJSONValueObjectAppendString; virJSONValueObjectAppendString;
virJSONValueObjectGet; virJSONValueObjectGet;
virJSONValueObjectGetBoolean; virJSONValueObjectGetBoolean;
virJSONValueObjectGetKey;
virJSONValueObjectGetNumberDouble; virJSONValueObjectGetNumberDouble;
virJSONValueObjectGetNumberInt; virJSONValueObjectGetNumberInt;
virJSONValueObjectGetNumberLong; virJSONValueObjectGetNumberLong;
virJSONValueObjectGetNumberUint; virJSONValueObjectGetNumberUint;
virJSONValueObjectGetNumberUlong; virJSONValueObjectGetNumberUlong;
virJSONValueObjectGetString; virJSONValueObjectGetString;
virJSONValueObjectGetValue;
virJSONValueObjectHasKey; virJSONValueObjectHasKey;
virJSONValueObjectIsNull; virJSONValueObjectIsNull;
virJSONValueObjectKeysNumber;
virJSONValueToString; virJSONValueToString;
......
...@@ -431,6 +431,36 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key) ...@@ -431,6 +431,36 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key)
return NULL; return NULL;
} }
int virJSONValueObjectKeysNumber(virJSONValuePtr object)
{
if (object->type != VIR_JSON_TYPE_OBJECT)
return -1;
return object->data.object.npairs;
}
const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned int n)
{
if (object->type != VIR_JSON_TYPE_OBJECT)
return NULL;
if (n >= object->data.object.npairs)
return NULL;
return object->data.object.pairs[n].key;
}
virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigned int n)
{
if (object->type != VIR_JSON_TYPE_OBJECT)
return NULL;
if (n >= object->data.object.npairs)
return NULL;
return object->data.object.pairs[n].value;
}
int virJSONValueArraySize(virJSONValuePtr array) int virJSONValueArraySize(virJSONValuePtr array)
{ {
if (array->type != VIR_JSON_TYPE_ARRAY) if (array->type != VIR_JSON_TYPE_ARRAY)
......
...@@ -100,6 +100,10 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key); ...@@ -100,6 +100,10 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
int virJSONValueArraySize(virJSONValuePtr object); int virJSONValueArraySize(virJSONValuePtr object);
virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element); virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
int virJSONValueObjectKeysNumber(virJSONValuePtr object);
const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned int n);
virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigned int n);
const char *virJSONValueGetString(virJSONValuePtr object); const char *virJSONValueGetString(virJSONValuePtr object);
int virJSONValueGetNumberInt(virJSONValuePtr object, int *value); int virJSONValueGetNumberInt(virJSONValuePtr object, int *value);
int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value); int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册