2 * gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
14 #include "json_inttypes.h"
15 #include "json_object.h"
16 #include "json_tokener.h"
17 #include "snprintf_compat.h"
19 void print_hex(const char *s)
23 while ((ch = *iter++) != 0)
33 static void test_lot_of_adds(void);
34 static void test_lot_of_adds(void)
38 json_object *jobj = json_object_new_object();
40 for (ii = 0; ii < 500; ii++)
42 snprintf(key, sizeof(key), "k%d", ii);
43 json_object *iobj = json_object_new_int(ii);
45 if (json_object_object_add(jobj, key, iobj))
47 fprintf(stderr, "FAILED to add object #%d\n", ii);
51 printf("%s\n", json_object_to_json_string(jobj));
52 assert(json_object_object_length(jobj) == 500);
53 json_object_put(jobj);
58 const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
59 const char *expected =
60 "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
61 struct json_object *parse_result = json_tokener_parse(input);
62 const char *unjson = json_object_get_string(parse_result);
64 printf("input: %s\n", input);
66 int strings_match = !strcmp(expected, unjson);
70 printf("JSON parse result is correct: %s\n", unjson);
75 printf("JSON parse result doesn't match expected string\n");
76 printf("expected string bytes: ");
78 printf("parsed string bytes: ");
83 json_object_put(parse_result);