From 1719796a3a10eccf91eadb38c019829110e96294 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Fri, 29 Jun 2018 11:20:51 +0800 Subject: update get_devices --- util.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 6cd56ac..020485c 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,6 @@ #include #include +#include "util.h" #define SLMAX 100 @@ -25,3 +26,23 @@ char * alloc_build_string(const char *ss[]) res[cur] = 0; return res; } + +const char *json_gets(json_object *j, const char *key) +{ + json_object *val; + + if (json_object_object_get_ex(j, key, &val)) { + if (json_object_is_type(val, json_type_string)) + return json_object_get_string(val); + } + return NULL; +} + +char *json_gets_dup(json_object *j, const char *key) +{ + const char *t = json_gets(j, key); + if (t == NULL) + return NULL; + else + return strdup(t); +} -- cgit v1.2.3