本文整理汇总了C++中JSON_NODE_TYPE函数的典型用法代码示例。如果您正苦于以下问题:C++ JSON_NODE_TYPE函数的具体用法?C++ JSON_NODE_TYPE怎么用?C++ JSON_NODE_TYPE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSON_NODE_TYPE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clr_oci_json_parse_aux
/*!
* Recursive function that handles converging \c JsonNode's to \c
* GNode's.
*
* \param root \c Root JsonNode to convert.
* \param node \c GNode.
* \param parsing_array \c true if handling an array, else \c false.
*/
static void
clr_oci_json_parse_aux(JsonNode* root, GNode* node, bool parsing_array) {
guint i;
g_assert (root);
g_assert (node);
if (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT) {
JsonObject *object = json_node_get_object(root);
if (object) {
guint j;
guint size;
GList* keys, *key = NULL;
GList* values, *value = NULL;
size = json_object_get_size(object);
keys = json_object_get_members(object);
values = json_object_get_values(object);
node = g_node_append(node, g_node_new(NULL));
for (j = 0, key = keys, value = values; j < size; j++) {
if (key) {
node = g_node_append(node->parent, g_node_new(g_strdup(key->data)));
}
if (value) {
clr_oci_json_parse_aux(value->data, node, false);
}
key = g_list_next(key);
value = g_list_next(value);
}
if (keys) {
g_list_free(keys);
}
if (values) {
g_list_free(values);
}
}
} else if (JSON_NODE_TYPE(root) == JSON_NODE_ARRAY) {
JsonArray* array = json_node_get_array(root);
guint array_size = json_array_get_length (array);
JsonNode *array_element;
for (i = 0; i < array_size; i++) {
array_element = json_array_get_element(array, i);
clr_oci_json_parse_aux(array_element, node, true);
}
} else if (JSON_NODE_TYPE(root) == JSON_NODE_VALUE) {
node = g_node_append(node, g_node_new(clr_oci_json_string(root)));
if (parsing_array) {
node = g_node_append(node, g_node_new(NULL));
}
}
}
示例2: json_reader_count_members
/**
* json_reader_count_members:
* @reader: a #JsonReader
*
* Counts the members of the current position, if @reader is
* positioned on an object
*
* Return value: the number of members, or -1. In case of failure
* the #JsonReader is set in an error state
*
* Since: 0.12
*/
gint
json_reader_count_members (JsonReader *reader)
{
JsonReaderPrivate *priv;
g_return_val_if_fail (JSON_IS_READER (reader), -1);
priv = reader->priv;
if (priv->current_node == NULL)
{
json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE,
_("No node available at the current position"));
return -1;
}
if (!JSON_NODE_HOLDS_OBJECT (priv->current_node))
{
json_reader_set_error (reader, JSON_READER_ERROR_NO_OBJECT,
_("The current position holds a '%s' and not an object"),
json_node_type_get_name (JSON_NODE_TYPE (priv->current_node)));
return -1;
}
return json_object_get_size (json_node_get_object (priv->current_node));
}
示例3: toHashTable
static GHashTable* toHashTable(std::string msg)
{
g_print("toHashTable\n");
JsonParser *parser;
GError *error = NULL;
parser = json_parser_new ();
GHashTable *map = g_hash_table_new(g_str_hash, g_str_equal);
if (json_parser_load_from_data (parser, msg.c_str(), -1, &error))
{
JsonNode *root;
JsonObject *object;
g_assert (NULL != json_parser_get_root (parser));
root = json_parser_get_root (parser);
if (JSON_NODE_TYPE (root) == JSON_NODE_OBJECT)
{
object = json_node_get_object (root);
g_assert (object != NULL);
json_object_foreach_member(object, parseMembers, map);
}
}
else
{
g_error_free (error);
}
g_object_unref (parser);
return map;
}
示例4: server_new_from_json
/**
* server_new_from_json:
* @object: JSON object with server definition
*
* Looks at the type and then uses a subclassed function to build the
* server.
*
* Return value: A new Server object or NULL if error
*/
Server *
server_new_from_json (JsonObject * object)
{
g_return_val_if_fail(object != NULL, NULL);
if (!json_object_has_member(object, "Protocol")) {
return NULL;
}
JsonNode * proto_node = json_object_get_member(object, "Protocol");
if (JSON_NODE_TYPE(proto_node) != JSON_NODE_VALUE) {
return NULL;
}
if (json_node_get_value_type(proto_node) != G_TYPE_STRING) {
return NULL;
}
const gchar * proto = json_node_get_string(proto_node);
Server * newserver = NULL;
if (g_strcmp0(proto, "ICA") == 0 || g_strcmp0(proto, "ica") == 0) {
newserver = citrix_server_new_from_json(object);
}
else if (g_strcmp0(proto, "freerdp") == 0 || g_strcmp0(proto, "rdp") == 0 || g_strcmp0(proto, "RDP") == 0 || g_strcmp0(proto, "FreeRDP") == 0) {
newserver = rdp_server_new_from_json(object);
}
else if (g_strcmp0(proto, "x2go") == 0 || g_strcmp0(proto, "X2go") == 0 || g_strcmp0(proto, "X2Go") == 0 || g_strcmp0(proto, "X2GO") == 0 || g_strcmp0(proto, "x2GO") == 0 || g_strcmp0(proto, "x2gO") == 0) {
newserver = x2go_server_new_from_json(object);
}
return newserver;
}
示例5: json_reader_get_string_value
/**
* json_reader_get_string_value:
* @reader: a #JsonReader
*
* Retrieves the string value of the current position of @reader
*
* Return value: the string value
*
* Since: 0.12
*/
const gchar *
json_reader_get_string_value (JsonReader *reader)
{
JsonNode *node;
g_return_val_if_fail (JSON_IS_READER (reader), NULL);
json_reader_return_val_if_error_set (reader, NULL);
if (reader->priv->current_node == NULL)
{
json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE,
_("No node available at the current position"));
return NULL;
}
node = reader->priv->current_node;
if (!JSON_NODE_HOLDS_VALUE (node))
{
json_reader_set_error (reader, JSON_READER_ERROR_NO_VALUE,
_("The current position holds a '%s' and not a value"),
json_node_type_get_name (JSON_NODE_TYPE (node)));
return NULL;
}
if (json_node_get_value_type (node) != G_TYPE_STRING)
{
json_reader_set_error (reader, JSON_READER_ERROR_INVALID_TYPE,
_("The current position does not hold a string type"));
return NULL;
}
return json_node_get_string (reader->priv->current_node);
}
示例6: json_reader_get_boolean_value
/**
* json_reader_get_boolean_value:
* @reader: a #JsonReader
*
* Retrieves the boolean value of the current position of @reader
*
* Return value: the boolean value
*
* Since: 0.12
*/
gboolean
json_reader_get_boolean_value (JsonReader *reader)
{
JsonNode *node;
g_return_val_if_fail (JSON_IS_READER (reader), FALSE);
json_reader_return_val_if_error_set (reader, FALSE);
if (reader->priv->current_node == NULL)
{
json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE,
_("No node available at the current position"));
return FALSE;
}
node = reader->priv->current_node;
if (!JSON_NODE_HOLDS_VALUE (node))
{
json_reader_set_error (reader, JSON_READER_ERROR_NO_VALUE,
_("The current position holds a '%s' and not a value"),
json_node_type_get_name (JSON_NODE_TYPE (node)));
return FALSE;
}
return json_node_get_boolean (node);
}
示例7: json_node_get_value
/**
* json_node_get_value:
* @node: a #JsonNode
* @value: (out caller-allocates): return location for an uninitialized value
*
* Retrieves a value from a #JsonNode and copies into @value. When done
* using it, call g_value_unset() on the #GValue.
*/
void
json_node_get_value (JsonNode *node,
GValue *value)
{
g_return_if_fail (JSON_NODE_IS_VALID (node));
g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE);
if (node->data.value)
{
g_value_init (value, JSON_VALUE_TYPE (node->data.value));
switch (JSON_VALUE_TYPE (node->data.value))
{
case G_TYPE_INT64:
g_value_set_int64 (value, json_value_get_int (node->data.value));
break;
case G_TYPE_DOUBLE:
g_value_set_double (value, json_value_get_double (node->data.value));
break;
case G_TYPE_BOOLEAN:
g_value_set_boolean (value, json_value_get_boolean (node->data.value));
break;
case G_TYPE_STRING:
g_value_set_string (value, json_value_get_string (node->data.value));
break;
default:
break;
}
}
}
示例8: json_reader_count_elements
/**
* json_reader_count_elements:
* @reader: a #JsonReader
*
* Counts the elements of the current position, if @reader is
* positioned on an array
*
* Return value: the number of elements, or -1. In case of failure
* the #JsonReader is set in an error state
*
* Since: 0.12
*/
gint
json_reader_count_elements (JsonReader *reader)
{
JsonReaderPrivate *priv;
g_return_val_if_fail (JSON_IS_READER (reader), -1);
priv = reader->priv;
if (priv->current_node == NULL)
{
json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE,
_("No node available at the current position"));
return -1;
}
if (!JSON_NODE_HOLDS_ARRAY (priv->current_node))
{
json_reader_set_error (reader, JSON_READER_ERROR_NO_ARRAY,
_("The current position holds a '%s' and not an array"),
json_node_type_get_name (JSON_NODE_TYPE (priv->current_node)));
return -1;
}
return json_array_get_length (json_node_get_array (priv->current_node));
}
示例9: json_node_get_object
/**
* json_node_get_object:
* @node: a #JsonNode
*
* Retrieves the #JsonObject stored inside a #JsonNode
*
* Return value: (transfer none): the #JsonObject
*/
JsonObject *
json_node_get_object (JsonNode *node)
{
g_return_val_if_fail (JSON_NODE_IS_VALID (node), NULL);
g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_OBJECT, NULL);
return node->data.object;
}
示例10: json_node_get_array
/**
* json_node_get_array:
* @node: a #JsonNode
*
* Retrieves the #JsonArray stored inside a #JsonNode
*
* Return value: (transfer none): the #JsonArray
*/
JsonArray *
json_node_get_array (JsonNode *node)
{
g_return_val_if_fail (JSON_NODE_IS_VALID (node), NULL);
g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_ARRAY, NULL);
return node->data.array;
}
示例11: json_gobject_deserialize
/**
* json_gobject_deserialize:
* @gtype: the type of the #GObject to create
* @node: a #JsonNode of type %JSON_NODE_OBJECT describing the
* instance of type @gtype
*
* Creates a new #GObject of type @gtype, and constructs it
* using the members of the passed #JsonObject
*
* Return value: (transfer full): The newly created #GObject
* instance. Use g_object_unref() to free the resources
* allocated by this function
*
* Since: 0.10
*/
GObject *
json_gobject_deserialize (GType gtype,
JsonNode *node)
{
g_return_val_if_fail (g_type_is_a (gtype, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_OBJECT, NULL);
return json_gobject_new (gtype, json_node_get_object (node));
}
示例12: json_node_dup_array
/**
* json_node_dup_array:
* @node: a #JsonNode
*
* Retrieves the #JsonArray stored inside a #JsonNode and returns it
* with its reference count increased by one.
*
* Return value: (transfer full): the #JsonArray with its reference
* count increased.
*/
JsonArray *
json_node_dup_array (JsonNode *node)
{
g_return_val_if_fail (JSON_NODE_IS_VALID (node), NULL);
g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_ARRAY, NULL);
if (node->data.array)
return json_array_ref (node->data.array);
return NULL;
}
示例13: json_node_dup_object
/**
* json_node_dup_object:
* @node: a #JsonNode
*
* Retrieves the #JsonObject inside @node. The reference count of
* the returned object is increased.
*
* Return value: (transfer full): the #JsonObject
*/
JsonObject *
json_node_dup_object (JsonNode *node)
{
g_return_val_if_fail (JSON_NODE_IS_VALID (node), NULL);
g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_OBJECT, NULL);
if (node->data.object)
return json_object_ref (node->data.object);
return NULL;
}
示例14: twitter_user_list_build
static void
twitter_user_list_build (TwitterUserList *user_list,
JsonNode *node)
{
TwitterUserListPrivate *priv = user_list->priv;
JsonArray *array;
GList *elements, *l;
GList *list = NULL;
if (!node || JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
return;
array = json_node_get_array (node);
elements = json_array_get_elements (array);
for (l = elements; l != NULL; l = l->next)
{
JsonNode *element = l->data;
if (JSON_NODE_TYPE (element) == JSON_NODE_OBJECT)
{
TwitterUser *user;
guint user_id;
user = twitter_user_new_from_node (element);
user_id = twitter_user_get_id (user);
if (user_id == 0)
{
g_object_unref (user);
continue;
}
g_hash_table_replace (priv->user_by_id,
GUINT_TO_POINTER (user_id),
g_object_ref_sink (user));
list = g_list_prepend (list, user);
}
}
priv->user_list = g_list_reverse (list);
}
示例15: twitter_status_build
static void
twitter_status_build (TwitterStatus *status,
JsonNode *node)
{
TwitterStatusPrivate *priv = status->priv;
JsonObject *obj;
JsonNode *member;
if (!node || JSON_NODE_TYPE (node) != JSON_NODE_OBJECT)
return;
obj = json_node_get_object (node);
member = json_object_get_member (obj, "user");
if (member)
{
priv->user = twitter_user_new_from_node (member);
g_object_ref_sink (priv->user);
priv->user_changed_id = g_signal_connect (priv->user, "changed",
G_CALLBACK (user_changed_cb),
status);
}
member = json_object_get_member (obj, "source");
if (member)
priv->source = json_node_dup_string (member);
member = json_object_get_member (obj, "created_at");
if (member)
priv->created_at = json_node_dup_string (member);
member = json_object_get_member (obj, "id");
if (member)
priv->id = json_node_get_int (member);
member = json_object_get_member (obj, "truncated");
if (member)
priv->truncated = json_node_get_boolean (member);
member = json_object_get_member (obj, "text");
if (member)
priv->text = json_node_dup_string (member);
member = json_object_get_member (obj, "in_reply_to_user_id");
if (member)
priv->in_reply_to_user_id = json_node_get_int (member);
member = json_object_get_member (obj, "in_reply_to_status_id");
if (member)
priv->in_reply_to_status_id = json_node_get_int (member);
}