fix json parser key adding
This commit is contained in:
26
cworker.c
26
cworker.c
@@ -281,21 +281,21 @@ int cworker_handler(const cworker_t* worker, int socket) {
|
||||
jlexer_init(&lexer, &cache);
|
||||
jparser_init(&parser, &lexer);
|
||||
|
||||
//if (jparser_parse(&parser) < 0) {
|
||||
//log_error("Cannot parse json");
|
||||
//err = -1;
|
||||
//goto exit;
|
||||
//}
|
||||
if (jparser_parse(&parser) < 0) {
|
||||
log_error("Cannot parse json");
|
||||
err = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
int64_t id = 0;
|
||||
char* name = "none";
|
||||
|
||||
//if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||
//log_error("Cannot bind id");
|
||||
//}
|
||||
//if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||
//log_error("Cannot bind name");
|
||||
//}
|
||||
if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||
log_error("Cannot bind id");
|
||||
}
|
||||
if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||
log_error("Cannot bind name");
|
||||
}
|
||||
|
||||
|
||||
char* msg = NULL;
|
||||
@@ -305,7 +305,7 @@ int cworker_handler(const cworker_t* worker, int socket) {
|
||||
jblock_init(&jb);
|
||||
jblock_addstr(&jb, "message", msg);
|
||||
jblock_addbool(&jb, "error", false);
|
||||
jblock_addint(&jb, "id", 12);
|
||||
jblock_addint(&jb, "id", id);
|
||||
|
||||
|
||||
char* jsonstr = NULL;
|
||||
@@ -317,7 +317,7 @@ int cworker_handler(const cworker_t* worker, int socket) {
|
||||
//free(name);
|
||||
free(msg);
|
||||
|
||||
//exit:
|
||||
exit:
|
||||
jparser_destroy(&parser);
|
||||
jlexer_destroy(&lexer);
|
||||
rcache_destroy(&cache);
|
||||
|
||||
Reference in New Issue
Block a user