i am using
frozen.h for json files .. I want to read the book array info from
.json file into
an array of structs
***********
problem 1**********
.. struct book has a nested struct date which I want to access in .json file .. but the library won't allow me .. if you know a solution to my problem with frozen.h OR you'd recommend another library for json files in C that supports the following feature:
* read/write from/into json file and array of structs that has nested structs
*scans a string directly into C variables
* prints C variables directly into an output stream
* modifies an existing JSON string
*********
problem 2**********
when storing the book title in array[0].title for example the saved string is Automation only not Automation and Robotics
What I have tried:
#include <stdio.h>
#include "frozen.h"
#include <stdlib.h>
#include <string.h>
typedef struct
{
int day;
int month;
int year;
} dateStruct;
typedef struct
{
char title[10];
char author[10];
char publisher[10];
char ISBN[10];
dateStruct date;
int copies;
int current;
int times_borrowed;
} book;
int main()
{ book array[3];
char *content = json_fread("tmp.json");
int i, value, len = strlen(content);
struct json_token t;
for (i = 0; json_scanf_array_elem(content, len, ".book", i, &t) > 0; i++) {
json_scanf(t.ptr, t.len, "{title: %s}", &(ar[i].title));
printf("%s\n\n",array[i].title);
}
return 0;
}
==========the json file ============
Quote:
{
"book": [
{
"title": "Automation And Robotics",
"author": "Miltiadis Boboulos",
"publisher": "Academic Studies Press",
"ISBN": "978-87-7681-696-4",
"date" : [
{
"day":14
"month":12
"year":2017
} ],
"copies":5
"current":3
},
{
"title": "engineering",
"author": "Abimbola Windapo",
"publisher": "Allen & Unwin",
"ISBN": "978-87-403-0362-9",
"date" : [
{
"day":14
"month":12
"year":2017
} ],
"copies":7
"current":6
}
]
}