* The type is coerced to a json_bool if the passed object is not a json_bool.
* integer and double objects will return 0 if there value is zero
* or 1 otherwise. If the passed object is a string it will return
- * 1 if it has a non zero length. If any other object type is passed
- * 1 will be returned if the object is not NULL.
+ * 1 if it has a non zero length.
+ * If any other object type is passed 0 will be returned, even non-empty
+ * json_type_array and json_type_object objects.
*
* @param obj the json_object instance
* @returns a json_bool
\"int64_number\": 2147483649,\n\
\"negative_number\": -321321321,\n\
\"a_null\": null,\n\
+ \"empty_array\": [],\n\
+ \"nonempty_array\": [ 123 ],\n\
+ \"array_with_zero\": [ 0 ],\n\
+ \"empty_object\": {},\n\
+ \"nonempty_object\": { \"a\": 123 },\n\
}";
/* Note: 2147483649 = INT_MAX + 2 */
/* Note: 9223372036854775809 = INT64_MAX + 2 */
getit(new_obj, "int64_number");
getit(new_obj, "negative_number");
getit(new_obj, "a_null");
+ getit(new_obj, "empty_array");
+ getit(new_obj, "nonempty_array");
+ getit(new_obj, "array_with_zero");
+ getit(new_obj, "empty_object");
+ getit(new_obj, "nonempty_object");
// Now check the behaviour of the json_object_is_type() function.
printf("\n================================\n");
"int64_number": 2147483649,
"negative_number": -321321321,
"a_null": null,
+ "empty_array": [],
+ "nonempty_array": [ 123 ],
+ "array_with_zero": [ 0 ],
+ "empty_object": {},
+ "nonempty_object": { "a": 123 },
}
Result is not NULL
new_obj.string_of_digits json_object_get_type()=string
new_obj.a_null json_object_get_uint64()=0
new_obj.a_null json_object_get_boolean()=0
new_obj.a_null json_object_get_double()=0.000000
+new_obj.empty_array json_object_get_type()=array
+new_obj.empty_array json_object_get_int()=0
+new_obj.empty_array json_object_get_int64()=0
+new_obj.empty_array json_object_get_uint64()=0
+new_obj.empty_array json_object_get_boolean()=0
+new_obj.empty_array json_object_get_double()=0.000000
+new_obj.nonempty_array json_object_get_type()=array
+new_obj.nonempty_array json_object_get_int()=0
+new_obj.nonempty_array json_object_get_int64()=0
+new_obj.nonempty_array json_object_get_uint64()=0
+new_obj.nonempty_array json_object_get_boolean()=0
+new_obj.nonempty_array json_object_get_double()=0.000000
+new_obj.array_with_zero json_object_get_type()=array
+new_obj.array_with_zero json_object_get_int()=0
+new_obj.array_with_zero json_object_get_int64()=0
+new_obj.array_with_zero json_object_get_uint64()=0
+new_obj.array_with_zero json_object_get_boolean()=0
+new_obj.array_with_zero json_object_get_double()=0.000000
+new_obj.empty_object json_object_get_type()=object
+new_obj.empty_object json_object_get_int()=0
+new_obj.empty_object json_object_get_int64()=0
+new_obj.empty_object json_object_get_uint64()=0
+new_obj.empty_object json_object_get_boolean()=0
+new_obj.empty_object json_object_get_double()=0.000000
+new_obj.nonempty_object json_object_get_type()=object
+new_obj.nonempty_object json_object_get_int()=0
+new_obj.nonempty_object json_object_get_int64()=0
+new_obj.nonempty_object json_object_get_uint64()=0
+new_obj.nonempty_object json_object_get_boolean()=0
+new_obj.nonempty_object json_object_get_double()=0.000000
================================
json_object_is_type: null,boolean,double,int,object,array,string