Json.Reader¶
| Subclasses: | None | 
|---|
Methods¶
| Inherited: | GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| class | new(node) | 
| count_elements() | |
| count_members() | |
| end_element() | |
| end_member() | |
| get_boolean_value() | |
| get_double_value() | |
| get_error() | |
| get_int_value() | |
| get_member_name() | |
| get_null_value() | |
| get_string_value() | |
| get_value() | |
| is_array() | |
| is_object() | |
| is_value() | |
| list_members() | |
| read_element(index_) | |
| read_member(member_name) | |
| set_root(root) | 
Virtual Methods¶
| Inherited: | GObject.Object (7) | 
|---|
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
Class Details¶
- 
class Json.Reader(**kwargs)¶
- Bases: - GObject.Object- Abstract: - No - Structure: - Json.ReaderClass- The - JsonReaderstructure contains only private data and should be accessed using the provided API- New in version 0.12. - 
classmethod new(node)¶
- Parameters: - node ( - Json.Nodeor- None) – a- Json.Node, or- None- Returns: - the newly created - Json.Reader. Use- GObject.Object.unref() to release the allocated resources when done- Return type: - Json.Reader- Creates a new - Json.Reader. You can use this object to read the contents of the JSON tree starting from node- New in version 0.12. 
 - 
count_elements()¶
- Returns: - the number of elements, or -1. In case of failure the - Json.Readeris set in an error state- Return type: - int- Counts the elements of the current position, if self is positioned on an array - New in version 0.12. 
 - 
count_members()¶
- Returns: - the number of members, or -1. In case of failure the - Json.Readeris set in an error state- Return type: - int- Counts the members of the current position, if self is positioned on an object - New in version 0.12. 
 - 
end_element()¶
- Moves the cursor back to the previous node after being positioned inside an array - This function resets the error state of self, if any was set - New in version 0.12. 
 - 
end_member()¶
- Moves the cursor back to the previous node after being positioned inside an object - This function resets the error state of self, if any was set - New in version 0.12. 
 - 
get_boolean_value()¶
- Returns: - the boolean value - Return type: - bool- Retrieves the boolean value of the current position of self - New in version 0.12. 
 - 
get_double_value()¶
- Returns: - the floating point value - Return type: - float- Retrieves the floating point value of the current position of self - New in version 0.12. 
 - 
get_error()¶
- Returns: - the pointer to the error, or - None- Return type: - GLib.Erroror- None- Retrieves the - GLib.Errorcurrently set on self, if the- Json.Readeris in error state- New in version 0.12. 
 - 
get_int_value()¶
- Returns: - the integer value - Return type: - int- Retrieves the integer value of the current position of self - New in version 0.12. 
 - 
get_member_name()¶
- Returns: - the name of the member, or - None- Return type: - stror- None- Retrieves the name of the current member. - New in version 0.14. 
 - 
get_null_value()¶
- Returns: - Trueif ‘null’ is set, and- Falseotherwise- Return type: - bool- Checks whether the value of the current position of self is ‘null’ - New in version 0.12. 
 - 
get_string_value()¶
- Returns: - the string value - Return type: - str- Retrieves the string value of the current position of self - New in version 0.12. 
 - 
get_value()¶
- Returns: - a - Json.Node, or- None. The returned node is owned by the- Json.Readerand it should not be modified or freed directly- Return type: - Json.Nodeor- None- Retrieves the - Json.Nodeof the current position of self- New in version 0.12. 
 - 
is_array()¶
- Returns: - Trueif the- Json.Readeris on an array, and- Falseotherwise- Return type: - bool- Checks whether the self is currently on an array - New in version 0.12. 
 - 
is_object()¶
- Returns: - Trueif the- Json.Readeris on an object, and- Falseotherwise- Return type: - bool- Checks whether the self is currently on an object - New in version 0.12. 
 - 
is_value()¶
- Returns: - Trueif the- Json.Readeris on a value, and- Falseotherwise- Return type: - bool- Checks whether the self is currently on a value - New in version 0.12. 
 - 
list_members()¶
- Returns: - a newly allocated, - None-terminated array of strings holding the members name. Use- GLib.strfreev() when done.- Return type: - [ - str]- Retrieves a list of member names from the current position, if self is positioned on an object. - New in version 0.14. 
 - 
read_element(index_)¶
- Parameters: - index ( - int) – the index of the element- Returns: - Trueon success, and- Falseotherwise- Return type: - bool- Advances the cursor of self to the element index_ of the array or the object at the current position. - You can use the - Json.Reader.get_valuefamily of functions to retrieve the value of the element; for instance:- json_reader_read_element (reader, 0); int_value = json_reader_get_int_value (reader); - After reading the value, - Json.Reader.end_element() should be called to reposition the cursor inside the- Json.Reader, e.g.:- json_reader_read_element (reader, 1); str_value = json_reader_get_string_value (reader); json_reader_end_element (reader); json_reader_read_element (reader, 2); str_value = json_reader_get_string_value (reader); json_reader_end_element (reader); - If self is not currently on an array or an object, or if the index_ is bigger than the size of the array or the object, the - Json.Readerwill be put in an error state until- Json.Reader.end_element() is called. This means that if used conditionally,- Json.Reader.end_element() must be called on both code paths:- if (!json_reader_read_element (reader, 1)) { json_reader_end_element (reader); g_set_error (error, …); return FALSE; } str_value = json_reader_get_string_value (reader); json_reader_end_element (reader);- New in version 0.12. 
 - 
read_member(member_name)¶
- Parameters: - member_name ( - str) – the name of the member to read- Returns: - Trueon success, and- Falseotherwise- Return type: - bool- Advances the cursor of self to the member_name of the object at the current position. - You can use the - Json.Reader.get_valuefamily of functions to retrieve the value of the member; for instance:- json_reader_read_member (reader, "width"); width = json_reader_get_int_value (reader); - After reading the value, - Json.Reader.end_member() should be called to reposition the cursor inside the- Json.Reader, e.g.:- json_reader_read_member (reader, "author"); author = json_reader_get_string_value (reader); json_reader_end_member (reader); json_reader_read_member (reader, "title"); title = json_reader_get_string_value (reader); json_reader_end_member (reader); - If self is not currently on an object, or if the member_name is not defined in the object, the - Json.Readerwill be put in an error state until- Json.Reader.end_member() is called. This means that if used conditionally,- Json.Reader.end_member() must be called on both code paths:- if (!json_reader_read_member (reader, "title")) { json_reader_end_member (reader); g_set_error (error, …); return FALSE; } str_value = json_reader_get_string_value (reader); json_reader_end_member (reader);- New in version 0.12. 
 
- 
classmethod