Wizix Wizix - 9 months ago 20
JSON Question

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:

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:

"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
apparently. How can I check if my value is a boolean or not?


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.



In C you would probably use G_TYPE_BOOLEAN: