检查对象是否是布尔值

[英]Check if object is a boolean


I need to check if my Json.Object is a boolean or not. This is what I've done:

我需要检查我的Json.Object是否是布尔值。这就是我所做的:

var media = root.get_member ("media");
if (!media.get_value_type ().is_a (bool)) {
    this.media.set ("mp4", media.get_object ().get_string_member ("mp4"));
    this.media.set ("webm", media.get_object ().get_string_member ("webm"));
}

The JSON looks like this:

JSON看起来像这样:

"media": {
    "mp4": "http:\/\/img-9gag-fun.9cache.com\/photo\/EyVtjpq_460sv.mp4",
    "webm": "http:\/\/img-9gag-fun.9cache.com\/photo\/EyVtjpq_460svwm.webm"
},

Or like this if it's a boolean:

或者像这样,如果它是布尔值:

"media": false,

But this condition is not working !media.get_value_type ().is_a (bool), the method is_a () can't take bool apparently. How can I check if my value is a boolean or not?

但是这个条件不起作用!media.get_value_type()。is_a(bool),方法is_a()显然不能拿bool。如何检查我的值是否为布尔值?

1 个解决方案

#1


1  

Should be this:

应该是这样的:

if (media.get_value_type () != typeof(bool))

You can use typeof () to get the GType of any data type in Vala and GType is what the function returns.

您可以使用typeof()来获取Vala中任何数据类型的GType,GType就是函数返回的内容。

https://wiki.gnome.org/Projects/Vala/FAQ#How_do_I_get_the_GType_for_something.3F

https://developer.gnome.org/json-glib/stable/json-glib-JSON-Node.html#json-node-get-value-type

In C you would probably use G_TYPE_BOOLEAN:

在C中你可能会使用G_TYPE_BOOLEAN:

https://developer.gnome.org/gobject/stable/gobject-Type-Information.html#G-TYPE-BOOLEAN:CAPS


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2016/05/31/515efa38b97c25f487e8e914b27d4eb5.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号