-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonparser.cpp
More file actions
40 lines (33 loc) · 1.17 KB
/
jsonparser.cpp
File metadata and controls
40 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "jsonparser.h"
char* create_json_user(char *username, char *password) {
json user;
user["username"] = username;
user["password"] = password;
std::string json_string = user.dump(4);
char *return_string = (char *) calloc(json_string.length() + 1, sizeof(char));
std::strcpy(return_string, json_string.c_str());
return return_string;
}
char* create_json_book(char *title, char *author, char *genre, char *publisher,
int page_count) {
json book;
book["title"] = title;
book["author"] = author;
book["genre"] = genre;
book["publisher"] = publisher;
book["page_count"] = page_count;
std::string json_string = book.dump(4);
char *return_string = (char *) calloc(json_string.length() + 1, sizeof(char));
std::strcpy(return_string, json_string.c_str());
return return_string;
}
void get_token(char *json_string, char *buffer){
json json_object = json::parse(json_string);
std::string res = json_object["token"];
strcpy(buffer, res.c_str());
}
void parse_books_and_print(char *json_string) {
json books;
books = json::parse((json_string-1));
std::cout << books.dump(4) << "\n";
}