修改返回内容

This commit is contained in:
wang_chengh 2023-09-19 17:48:37 +08:00
parent dba3d23f8d
commit f5d792b8f2
1 changed files with 19 additions and 19 deletions

View File

@ -28,6 +28,7 @@ int main() {
}
if (mysql_query(conn,
"CREATE DATABASE if NOT EXISTS router;"
"CREATE TABLE IF NOT EXISTS users(id INT AUTO_INCREMENT "
"PRIMARY KEY "
"username VARCHAR(50) NOT NULL, password VARCHAR(255) NOT "
@ -86,30 +87,29 @@ int main() {
return 1;
}
cJSON *result_json = cJSON_CreateObject();
if ((row = mysql_fetch_row(res))) {
cJSON_AddNumberToObject(result_json, "code", 0);
} else {
cJSON_AddNumberToObject(result_json, "code", 1);
cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误");
}
/* if ((row = mysql_fetch_row(res))) {
cJSON_AddStringToObject(result_json, "code", 0);
} else {
cJSON_AddStringToObject(result_json, "msg", "登录失败");
} */
char *result_json_string = cJSON_Print(result_json);
// cJSON *result_json = cJSON_CreateObject();
// 输出 JSON 结果
printf("content-type: application/json;charset=utf-8\r\n");
printf("\r\n");
printf("%s\n", result_json_string);
free(result_json_string);
cJSON_Delete(result_json);
if ((row = mysql_fetch_row(res))) {
// cJSON_AddNumberToObject(result_json, "code", 0);
printf(
"{\"code\": 0, \"data\": {\"user_id\": 111, \"nickName\": "
"\"老狄\"}}");
} else {
printf("{\"code\": 1, \"msg\": \"用户名或口令错误\"}");
// cJSON_AddNumberToObject(result_json, "code", 1);
// cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误");
}
// char *result_json_string = cJSON_Print(result_json);
// printf("%s\n", result_json_string);
// free(result_json_string);
// cJSON_Delete(result_json);
cJSON_Delete(p);
mysql_free_result(res);
mysql_close(conn);