Advertisement
rotrevrep

JSON Node get

Oct 9th, 2015
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. JsonNode* json_node_get (JsonNode* node, GValue* value) {
  2.     g_return_val_if_fail (node != NULL, NULL);
  3.     g_return_val_if_fail (val != NULL, NULL);
  4.     GType type = G_VALUE_TYPE (val);
  5.     JsonNode* result = NULL;
  6.     JsonNodeType jtype = json_node_get_node_type (node);
  7.     if (jtype == JSON_NODE_OBJECT && type == G_TYPE_STRING) {
  8.         const gchar* key = g_value_get_string (value);
  9.         JsonObject* object = json_node_get_object (node);
  10.         result = json_object_get_member (object, key);
  11.     }
  12.     if (jtype == JSON_NODE_ARRAY && (type == G_TYPE_INT || type == G_TYPE_UINT)) {
  13.         guint index = 0;
  14.         if (type == G_TYPE_INT)
  15.             index = (guint)g_value_get_int (value);
  16.         else
  17.             index = g_value_get_uint (value);
  18.         JsonArray* array = json_node_get_array (node);
  19.         result = json_array_get_element (array, index);
  20.     }
  21.     return NULL;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement