Browse code

modified json_api functions to exhibit the same behavior

Kevin Lin authored on 2014/06/26 02:11:00
Showing 1 changed files
... ...
@@ -224,10 +224,7 @@ json_object *cli_jsonarray(json_object *obj, const char *key)
224 224
 {
225 225
     json_object *newobj;
226 226
 
227
-    if (!(key))
228
-        return NULL;
229
-
230
-    if (obj) {
227
+    if (obj && key) {
231 228
         /* First check to see if this key exists */
232 229
         newobj = json_object_object_get(obj, key);
233 230
         if (newobj)
... ...
@@ -238,7 +235,7 @@ json_object *cli_jsonarray(json_object *obj, const char *key)
238 238
     if (!(newobj))
239 239
         return NULL;
240 240
 
241
-    if (obj) {
241
+    if (obj && key) {
242 242
         json_object_object_add(obj, key, newobj);
243 243
         newobj = json_object_object_get(obj, key);
244 244
     }
... ...
@@ -278,8 +275,10 @@ json_object *cli_jsonobj(json_object *obj, const char *key)
278 278
     if (!(newobj))
279 279
         return NULL;
280 280
 
281
-    if (obj && key)
281
+    if (obj && key) {
282 282
         json_object_object_add(obj, key, newobj);
283
+        newobj = json_object_object_get(obj, key);
284
+    }
283 285
 
284 286
     return newobj;
285 287
 }