当前位置: 首页 > news >正文

承德 网站建设 网络推广 网页设计wordpress博客主题手机

承德 网站建设 网络推广 网页设计,wordpress博客主题手机,邯郸学校网站建设,wordpress 主题 汉化目标#xff1a;设计数据库表表格式#xff0c;将“indicatorTree-v10.json”导入到数据库#xff0c;再从数据库读取写为JSON文件。 其他要求#xff1a;数据库要求为mysql数据库#xff1b;编程语言暂时限定为C#xff1b;JSON解析使用本文件夹中的cJSON.c和cJSON.h设计数据库表表格式将“indicatorTree-v10.json”导入到数据库再从数据库读取写为JSON文件。 其他要求数据库要求为mysql数据库编程语言暂时限定为CJSON解析使用本文件夹中的cJSON.c和cJSON.h代码编写风格严格按照“TDYTH编程规范_20220527_C.doc”。 提示可使用递归写法也可以自己构建栈结构。gcc编译的Makefile文件参考“Makefile参考”。 数据库表设计 CREATE TABLE Indicator (id varchar(10) NOT NULL,abilityName varchar(255) DEFAULT NULL,level int DEFAULT NULL,defaultWeight float DEFAULT NULL,area text,devType text,technologicalSystem text,enable tinyint(1) DEFAULT NULL,parent_id varchar(10) DEFAULT NULL,PRIMARY KEY (id),KEY parent_id (parent_id),CONSTRAINT Indicator_ibfk_1 FOREIGN KEY (parent_id) REFERENCES Indicator (id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;CREATE TABLE CalculateParams (id int NOT NULL AUTO_INCREMENT,indicator_id varchar(10) DEFAULT NULL,param_key varchar(255) DEFAULT NULL,param_value text,PRIMARY KEY (id),KEY indicator_id (indicator_id),CONSTRAINT CalculateParams_ibfk_1 FOREIGN KEY (indicator_id) REFERENCES Indicator (id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;CREATE TABLE IndicatorSystem (id varchar(10) NOT NULL,name varchar(255) DEFAULT NULL,description text,PRIMARY KEY (id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;C 代码示例 使用cJSON库来解析JSON文件并将数据插入到数据库中。 #include stdio.h #include stdlib.h #include string.h #include mysql/mysql.h #include cJSON.h// 插入 Indicator 表 void insert_indicator(cJSON *indicator, MYSQL *conn, const char *parent_id) {cJSON *id cJSON_GetObjectItem(indicator, id);cJSON *abilityName cJSON_GetObjectItem(indicator, abilityName);cJSON *level cJSON_GetObjectItem(indicator, level);cJSON *defaultWeight cJSON_GetObjectItem(indicator, defaultWeight);cJSON *enable cJSON_GetObjectItem(indicator, enable);char query[2048];char parent_id_str[64];if (parent_id) {snprintf(parent_id_str, sizeof(parent_id_str), %s, parent_id);} else {snprintf(parent_id_str, sizeof(parent_id_str), NULL);}snprintf(query, sizeof(query),INSERT INTO Indicator (id, abilityName, level, defaultWeight, enable, parent_id) VALUES (%s, %s, %d, %f, %d, %s) ON DUPLICATE KEY UPDATE abilityNameVALUES(abilityName), levelVALUES(level), defaultWeightVALUES(defaultWeight), enableVALUES(enable), parent_idVALUES(parent_id),cJSON_GetStringValue(id), cJSON_GetStringValue(abilityName), level-valueint,defaultWeight-valuedouble, enable-valueint, parent_id_str);printf(Executing query: %s\n, query);if (mysql_query(conn, query)) {fprintf(stderr, Insert error: %s\n, mysql_error(conn));exit(1);}cJSON *children cJSON_GetObjectItem(indicator, indicator);if (cJSON_IsArray(children)) {cJSON *child;cJSON_ArrayForEach(child, children) {insert_indicator(child, conn, cJSON_GetStringValue(id));}} }// 插入 CalculateParams 表 void insert_calculate_params(cJSON *params, MYSQL *conn) {cJSON *id cJSON_GetObjectItem(params, id);cJSON *indicator_id cJSON_GetObjectItem(params, indicator_id);cJSON *param_key cJSON_GetObjectItem(params, param_key);cJSON *param_value cJSON_GetObjectItem(params, param_value);char query[1024];snprintf(query, sizeof(query),INSERT INTO CalculateParams (id, indicator_id, param_key, param_value) VALUES (%s, %s, %s, %s) ON DUPLICATE KEY UPDATE param_keyVALUES(param_key), param_valueVALUES(param_value),cJSON_GetStringValue(id), cJSON_GetStringValue(indicator_id),cJSON_GetStringValue(param_key), cJSON_GetStringValue(param_value));if (mysql_query(conn, query)) {fprintf(stderr, Insert error: %s\n, mysql_error(conn));exit(1);} }// 插入 IndicatorSystem 表 void insert_indicator_system(cJSON *system, MYSQL *conn) {cJSON *id cJSON_GetObjectItem(system, id);cJSON *name cJSON_GetObjectItem(system, name);cJSON *description cJSON_GetObjectItem(system, description);char query[1024];snprintf(query, sizeof(query),INSERT INTO IndicatorSystem (id, name, description) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE nameVALUES(name), descriptionVALUES(description),cJSON_GetStringValue(id), cJSON_GetStringValue(name), cJSON_GetStringValue(description));if (mysql_query(conn, query)) {fprintf(stderr, Insert error: %s\n, mysql_error(conn));exit(1);} }// 从数据库中获取 Indicator 数据 cJSON* fetch_indicators(MYSQL *conn, const char *parent_id) {char query[1024];snprintf(query, sizeof(query), SELECT id, abilityName, level, defaultWeight, enable FROM Indicator WHERE parent_id %s,parent_id ? : IS NULL);if (parent_id) {strcat(query, parent_id);strcat(query, );}if (mysql_query(conn, query)) {fprintf(stderr, Select error: %s\n, mysql_error(conn));exit(1);}MYSQL_RES *result mysql_store_result(conn);if (result NULL) {fprintf(stderr, mysql_store_result() failed\n);exit(1);}MYSQL_ROW row;cJSON *json_array cJSON_CreateArray();while ((row mysql_fetch_row(result))) {cJSON *indicator cJSON_CreateObject();cJSON_AddStringToObject(indicator, id, row[0]);cJSON_AddStringToObject(indicator, abilityName, row[1]);cJSON_AddNumberToObject(indicator, level, atoi(row[2]));cJSON_AddNumberToObject(indicator, defaultWeight, atof(row[3]));cJSON_AddBoolToObject(indicator, enable, atoi(row[4]));cJSON *children fetch_indicators(conn, row[0]);cJSON_AddItemToObject(indicator, indicator, children);cJSON_AddItemToArray(json_array, indicator);}mysql_free_result(result);return json_array; }int main() {MYSQL *conn mysql_init(NULL);if (conn NULL) {fprintf(stderr, mysql_init() failed\n);return EXIT_FAILURE;}if (mysql_real_connect(conn, 192.168.84.1, root, ***, ***, 0, NULL, 0) NULL) {fprintf(stderr, mysql_real_connect() failed\n);mysql_close(conn);return EXIT_FAILURE;}FILE *file fopen(indicatorTree-v10.json, r);if (!file) {fprintf(stderr, Could not open file\n);return EXIT_FAILURE;}fseek(file, 0, SEEK_END);long length ftell(file);fseek(file, 0, SEEK_SET);char *data malloc(length);if (data NULL) {fprintf(stderr, Memory allocation failed\n);return EXIT_FAILURE;}fread(data, 1, length, file);fclose(file);cJSON *json cJSON_Parse(data);if (!json) {fprintf(stderr, Error parsing JSON\n);free(data);return EXIT_FAILURE;}cJSON *indicatorList cJSON_GetObjectItem(json, indicator);if (cJSON_IsArray(indicatorList)) {cJSON *indicator;cJSON_ArrayForEach(indicator, indicatorList) {insert_indicator(indicator, conn, NULL);}}cJSON *calculateParamsList cJSON_GetObjectItem(json, calculateParams);if (cJSON_IsArray(calculateParamsList)) {cJSON *param;cJSON_ArrayForEach(param, calculateParamsList) {insert_calculate_params(param, conn);}}cJSON *indicatorSystemsList cJSON_GetObjectItem(json, indicatorSystems);if (cJSON_IsArray(indicatorSystemsList)) {cJSON *system;cJSON_ArrayForEach(system, indicatorSystemsList) {insert_indicator_system(system, conn);}}free(data);cJSON_Delete(json);cJSON *json_array fetch_indicators(conn, NULL);char *json_string cJSON_Print(json_array);printf(%s\n, json_string);cJSON_Delete(json_array);free(json_string);mysql_close(conn);return EXIT_SUCCESS; }
http://www.sczhlp.com/news/214597/

相关文章:

  • 毕业设计除了网站还可以做啥商务网站教程
  • 网站线下服务中心建设方案免费推广网站在线
  • 免费安全建网站html5 微网站布局
  • 简洁 手机 导航网站模板下载安装推广seo是什么意思
  • 建设一个网站需要哪些功能互联网营销平台有哪些
  • 适配网站建设模版备案用的网站建设规划书怎么写
  • 网站怎么做来流量吗wordpress 主图截图
  • 宜昌教育云网站建设个人工作室网站怎么做
  • 获取网站访客qq网站建设模板能实现按钮跳转吗
  • 做新闻的网站怎样赚钱网络规划设计师报考
  • 西宁企业网站开发定制wordpress用户前台删除文章
  • 摄影网站的规划与设计仕德伟做的网站
  • 成都 地铁 建设 网站医院网站备案流程
  • 个人网站域名怎么取计算机前端培训机构哪个好
  • 标书制作简单吗网站优化升级
  • 商丘seo排名银川seo公司
  • 西安网站托管wordpress怎么设置侧滑栏
  • 网站建设完整教程视频教程阜宁网站制作选哪家
  • 旅游景区网站建设的必要性app商城开发网站建设
  • 广州网站vi设计报价wordpress 调用备案号
  • 运输网站建设有网站怎么建设手机站
  • 企业网站seo优化方案wordpress分类目录伪静态
  • 中国建设银行官方网站手机银行阜南做网站
  • 万网的网站建设好吗搜索引擎大全
  • 建设主管部门指定网站广州室内设计公司排名
  • 做新媒体国外网站企业网站制作哪些公司制作
  • 厦门网站建设合同农安县住房和城乡建设厅网站
  • 怎么让自己做的网站别人可以访问网站建设培训一般多少钱
  • 花生壳内网穿透网站如何做seo优化wordpress登不进后台
  • 东莞易进网络专业网站建设 网站网页设计欣赏app