Improve JSON output
This commit is contained in:
parent
8606c034e4
commit
9d74bab6ae
8
main.c
8
main.c
@ -105,15 +105,21 @@ sendbooks(struct kreq *r)
|
||||
kjson_open(&req, r);
|
||||
kjson_obj_open(&req);
|
||||
if (NULL == b) {
|
||||
kjson_putstringp(&req, "data", "error");
|
||||
kjson_objp_open(&req, "error");
|
||||
kjson_putstringp(&req, "msg", "Unknown book");
|
||||
kjson_obj_close(&req);
|
||||
} else {
|
||||
kjson_objp_open(&req, "book");
|
||||
kjson_putstringp(&req, "data", "books");
|
||||
kjson_putintp(&req, "id", b->id);
|
||||
kjson_putstringp(&req, "title", b->title);
|
||||
kjson_obj_close(&req);
|
||||
}
|
||||
#ifdef __DEBUG__
|
||||
kjson_putstringp(&req, "_path", r->path);
|
||||
kjson_putstringp(&req, "_pname", r->pname);
|
||||
kjson_putstringp(&req, "_pagename", r->pagename);
|
||||
#endif
|
||||
kjson_obj_close(&req);
|
||||
kjson_close(&req);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user