Callbacks¶
|
|
|
|
|
|
|
Details¶
- Json.ArrayForeach(array, index_, element_node, *user_data)¶
- Parameters:
array (
Json.Array
) – the iterated JSON arrayindex (
int
) – the index of the elementelement_node (
Json.Node
) – the value of the element at the given index_
The function to be passed to [method`Json`.Array.foreach_element].
You should not add or remove elements to and from array within this function.
It is safe to change the value of element_node.
New in version 0.8.
- Json.BoxedDeserializeFunc(node)¶
- Parameters:
node (
Json.Node
) – a node tree representing a boxed data- Returns:
the newly created boxed structure
- Return type:
Deserializes the contents of the passed
JsonNode
into aGBoxed
, for instance:```c static
object
my_point_deserialize (Json.Node
*node) { double x = 0.0, y = 0.0;if (JSON_NODE_HOLDS_ARRAY (node)) {
Json.Array
*array =Json.Node.get_array
(node);if (
Json.Array.get_length
(array) == 2) { x =Json.Array.get_double_element
(array, 0); y =Json.Array.get_double_element
(array, 1); } } else if (JSON_NODE_HOLDS_OBJECT (node)) {Json.Object
*obj =Json.Node.get_object
(node);x =
Json.Object.get_double_member_with_default
(obj, “x”, 0.0); y =Json.Object.get_double_member_with_default
(obj, “y”, 0.0); }// my_point_new() is defined elsewhere return my_point_new (x, y); } ```
New in version 0.10.
- Json.BoxedSerializeFunc(boxed)¶
- Parameters:
- Returns:
the newly created JSON node tree representing the boxed data
- Return type:
Serializes the passed
GBoxed
and stores it inside aJsonNode
, for instance:```c static
Json.Node
* my_point_serialize (gconstpointer boxed) { const MyPoint *point = boxed;g_autoptr(
Json.Builder
) builder =Json.Builder.new
();Json.Builder.begin_object
(builder);Json.Builder.set_member_name
(builder, “x”);Json.Builder.add_double_value
(builder, point->x);Json.Builder.set_member_name
(builder, “y”);Json.Builder.add_double_value
(builder, point->y);Json.Builder.end_object
(builder);return
Json.Builder.get_root
(builder); } ```New in version 0.10.
- Json.ObjectForeach(object, member_name, member_node, *user_data)¶
- Parameters:
object (
Json.Object
) – the iterated JSON objectmember_name (
str
) – the name of the membermember_node (
Json.Node
) – the value of the member
The function to be passed to [method`Json`.Object.foreach_member].
You should not add or remove members to and from object within this function.
It is safe to change the value of member_node.
New in version 0.8.