jansson #5

Merged
emilyd merged 5 commits from jansson into main 2023-07-21 13:59:04 +00:00
Showing only changes of commit 27cdc9cc0b - Show all commits

View File

@ -92,15 +92,24 @@ int main(int argc, char **argv) {
if (res.body[i] == '\n') {
if (lastWasNewline) {
printf("Headers end at: %i\n", i);
int rBL = resBodyLength - i;
char* body = malloc(rBL);
for (int j = 0; j < rBL; j++) {
body[j] = res.body[j + i + 1];
}
printf("\"%s\"\n", body);
json_error_t error;
json_t *root = json_loads(body, 0, &error);
if (!root || !json_is_array(root)) {
printf("failed decoding\n");
}
else {
printf("%s\n", body);
for (int j = 0; j < json_array_size(root); j++) {
json_t *data = json_array_get(root, j);
printf("%s\n", json_string_value(data));
}
}
break;
}