fixed array parsing and windows support
This commit is contained in:
parent
d2fe432828
commit
018442a445
5 changed files with 58 additions and 66 deletions
26
src/main.c
26
src/main.c
|
@ -81,6 +81,7 @@ int main(int argc, char **argv) {
|
|||
fread(buf, 1, length, input_file);
|
||||
buf[length] = '\0';
|
||||
|
||||
// parse the file
|
||||
size_t offset = 0;
|
||||
JsonObject *json = json_parse(buf, &offset);
|
||||
if (json == NULL) {
|
||||
|
@ -88,20 +89,19 @@ int main(int argc, char **argv) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("title: %s\n", (char*)json_get(json, "title"));
|
||||
printf("type: %s\n", (char*)json_get(json, "type"));
|
||||
printf("year: %.0f\n", *(float*)json_get(json, "year"));
|
||||
printf("artwork: %s\n", (char*)json_get(json, "artwork"));
|
||||
printf("buylink: %s\n", (char*)json_get(json, "buylink"));
|
||||
printf("title: %s\n", (char*)((JsonObject*)json_get(json, "title"))->value);
|
||||
printf("type: %s\n", (char*)((JsonObject*)json_get(json, "type"))->value);
|
||||
printf("year: %.0f\n", *(float*)((JsonObject*)json_get(json, "year"))->value);
|
||||
printf("artwork: %s\n", (char*)((JsonObject*)json_get(json, "artwork"))->value);
|
||||
printf("buylink: %s\n", (char*)((JsonObject*)json_get(json, "buylink"))->value);
|
||||
|
||||
JsonArrayItem *links = json_get(json, "links");
|
||||
size_t i = 0;
|
||||
while (links != NULL) {
|
||||
JsonObject *link = links->value;
|
||||
printf("links.%zu.title: %s\n", i, (char*)json_get(link, "title"));
|
||||
printf("links.%zu.url: %s\n", i, (char*)json_get(link, "url"));
|
||||
links = links->next;
|
||||
i++;
|
||||
JsonObject *links = (JsonObject*)json_get(json, "links");
|
||||
for (size_t i = 0; i < links->length; i++) {
|
||||
char path[256];
|
||||
sprintf(path, "links.%zu.title", i);
|
||||
printf("%s: %s\n", path, (char*)((JsonObject*)json_get(json, path))->value);
|
||||
sprintf(path, "links.%zu.url", i);
|
||||
printf("%s: %s\n", path, (char*)((JsonObject*)json_get(json, path))->value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue