From 934213c1b5cf59866cf9bf6864b4525a382bb5e0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 21 Jul 2020 15:26:06 +0200 Subject: [PATCH] Added functions Json::get_*. --- src/json.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/json.h | 4 ++++ 2 files changed, 52 insertions(+) diff --git a/src/json.c b/src/json.c index c6cdb9c..8968e62 100644 --- a/src/json.c +++ b/src/json.c @@ -21,3 +21,51 @@ #endif #include "json.h" + +gint +zak_utils_json_get_integer (JsonReader *reader, const gchar *name) +{ + gint ret; + + json_reader_read_member (reader, name); + ret = json_reader_get_int_value (reader); + json_reader_end_member (reader); + + return ret; +} + +gdouble +zak_utils_json_get_double (JsonReader *reader, const gchar *name) +{ + gdouble ret; + + json_reader_read_member (reader, name); + ret = json_reader_get_double_value (reader); + json_reader_end_member (reader); + + return ret; +} + +const gchar +*zak_utils_json_get_string (JsonReader *reader, const gchar *name) +{ + const gchar *ret; + + json_reader_read_member (reader, name); + ret = json_reader_get_string_value (reader); + json_reader_end_member (reader); + + return ret; +} + +gboolean +zak_utils_json_get_boolean (JsonReader *reader, const gchar *name) +{ + gboolean ret; + + json_reader_read_member (reader, name); + ret = json_reader_get_boolean_value (reader); + json_reader_end_member (reader); + + return ret; +} diff --git a/src/json.h b/src/json.h index 161aa38..9fbe3b0 100644 --- a/src/json.h +++ b/src/json.h @@ -29,6 +29,10 @@ G_BEGIN_DECLS +gint zak_utils_json_get_integer (JsonReader *reader, const gchar *name); +gdouble zak_utils_json_get_double (JsonReader *reader, const gchar *name); +const gchar *zak_utils_json_get_string (JsonReader *reader, const gchar *name); +gboolean zak_utils_json_get_boolean (JsonReader *reader, const gchar *name); G_END_DECLS -- 2.49.0