json.types
D types for json1 library
Types 8
The function to be passed to [json.array.Array.foreachElement].
You should not add or remove elements to and from array within this function.
It is safe to change the value of element_node.
Parameters
array | the iterated JSON array |
index | the index of the element |
elementNode | the value of the element at the given index_ |
Deserializes the contents of the passed [json.node.Node] into a GBoxed, for instance:
static gpointer
my_point_deserialize (JsonNode *node)
{
double x = 0.0, y = 0.0;
if (JSON_NODE_HOLDS_ARRAY (node))
{
JsonArray *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))
{
JsonObject *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);
}Parameters
node | a node tree representing a boxed data |
Returns
Serializes the passed GBoxed and stores it inside a [json.node.Node], for instance:
static JsonNode *
my_point_serialize (gconstpointer boxed)
{
const MyPoint *point = boxed;
g_autoptr(JsonBuilder) 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);
}Parameters
boxed | a boxed data structure |
Returns
The function to be passed to [json.object.ObjectWrap.foreachMember].
You should not add or remove members to and from object within this function.
It is safe to change the value of member_node.
Parameters
object | the iterated JSON object |
memberName | the name of the member |
memberNode | the value of the member |
Variables 4
MAJOR_VERSION = 1Json major version component (e.g. 1 if JSON_VERSION is "1.2.3")
MICRO_VERSION = 0Json micro version component (e.g. 3 if JSON_VERSION is "1.2.3")
MINOR_VERSION = 8Json minor version component (e.g. 2 if JSON_VERSION is "1.2.3")
VERSION_S = "1.8.0"The version of JSON-GLib, encoded as a string, useful for printing and concatenation.