Browse Source

add json_object_new_null

tags/json-c-0.14-20200419
dota17 5 years ago
parent
commit
010f33d460
9 changed files with 21 additions and 1 deletions
  1. +5
    -0
      json_object.c
  2. +5
    -0
      json_object.h
  3. +5
    -1
      tests/test1.c
  4. +1
    -0
      tests/test1.expected
  5. +1
    -0
      tests/test1Formatted_plain.expected
  6. +1
    -0
      tests/test1Formatted_pretty.expected
  7. +1
    -0
      tests/test1Formatted_spaced.expected
  8. +1
    -0
      tests/test1Formatted_spaced_pretty.expected
  9. +1
    -0
      tests/test1Formatted_spaced_pretty_pretty_tab.expected

+ 5
- 0
json_object.c View File

@@ -1275,6 +1275,11 @@ static int json_array_equal(struct json_object* jso1,
return 1; return 1;
} }


struct json_object* json_object_new_null()
{
return NULL;
}

static int json_object_all_values_equal(struct json_object* jso1, static int json_object_all_values_equal(struct json_object* jso1,
struct json_object* jso2) struct json_object* jso2)
{ {


+ 5
- 0
json_object.h View File

@@ -965,6 +965,11 @@ JSON_EXPORT int json_object_set_string(json_object* obj, const char* new_value);
*/ */
JSON_EXPORT int json_object_set_string_len(json_object* obj, const char* new_value, int len); JSON_EXPORT int json_object_set_string_len(json_object* obj, const char* new_value, int len);


/** Create a new empty json_object of type null and return NULL.
*
*/
JSON_EXPORT struct json_object* json_object_new_null();

/** Check if two json_object's are equal /** Check if two json_object's are equal
* *
* If the passed objects are equal 1 will be returned. * If the passed objects are equal 1 will be returned.


+ 5
- 1
tests/test1.c View File

@@ -137,7 +137,7 @@ void test_array_del_idx()


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
json_object *my_string, *my_int, *my_object, *my_array;
json_object *my_string, *my_int, *my_null, *my_object, *my_array;
size_t i; size_t i;
#ifdef TEST_FORMATTED #ifdef TEST_FORMATTED
int sflags = 0; int sflags = 0;
@@ -179,6 +179,9 @@ int main(int argc, char **argv)
printf("my_int=%d\n", json_object_get_int(my_int)); printf("my_int=%d\n", json_object_get_int(my_int));
printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int)); printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));


my_null = json_object_new_null();
printf("my_null.to_string()=%s\n", json_object_to_json_string(my_null));

my_array = json_object_new_array(); my_array = json_object_new_array();
json_object_array_add(my_array, json_object_new_int(1)); json_object_array_add(my_array, json_object_new_int(1));
json_object_array_add(my_array, json_object_new_int(2)); json_object_array_add(my_array, json_object_new_int(2));
@@ -249,6 +252,7 @@ int main(int argc, char **argv)


json_object_put(my_string); json_object_put(my_string);
json_object_put(my_int); json_object_put(my_int);
json_object_put(my_null);
json_object_put(my_object); json_object_put(my_object);
json_object_put(my_array); json_object_put(my_array);




+ 1
- 0
tests/test1.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


+ 1
- 0
tests/test1Formatted_plain.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


+ 1
- 0
tests/test1Formatted_pretty.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


+ 1
- 0
tests/test1Formatted_spaced.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


+ 1
- 0
tests/test1Formatted_spaced_pretty.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


+ 1
- 0
tests/test1Formatted_spaced_pretty_pretty_tab.expected View File

@@ -12,6 +12,7 @@ my_string=foo
my_string.to_string()="foo" my_string.to_string()="foo"
my_int=9 my_int=9
my_int.to_string()=9 my_int.to_string()=9
my_null.to_string()=null
my_array= my_array=
[0]=1 [0]=1
[1]=2 [1]=2


Loading…
Cancel
Save