参数组装



参数:

{ "isNewFlow":"1", "requestSysId":1423210758571, "requestSysName":"FMS", "taskComp":"PA011_S000000205", "taskDept":"PA011_S000033562", "taskDeptName":"集团行政组", "taskDesc":"我来测试万里通", "taskDetailList":[{"flowOwner":"PAICDOM\\ZHONGXIANGBO952", "handType":"30", "nodeDesc":"第一步审批", "seq":"1"}, {"flowOwner":"PAICDOM\\CAIJING1", "handType":"30", "nodeDesc":"第二步审批", "seq":"2"}], "taskFileList":[{"contentType":"html", "docClass":"FMSClass_url", "docName":"http://cnsz020118:5000/Page/Standard/StandardInfoForEoa.aspx?ID=a6c1657a-11a2-4355-8f8c-db36dd88d9e6", "docOldName":"测试附件链接地址", "fileSize":"50", "operator":"中向波", "requestSysId":1423210758571, "requestSysName":"FMS"}], "taskName":"万里通测试", "taskOwner":"PAICDOM\\ZHANGWENTAO446", "taskSendLeader":"审批领导", "taskSortId":"1", "taskTransactor":"ZHANGWENTAO446 650249" }


平安api: http://api.pingan.com/wiki/viewApiInfo.do?id=112238C6B41A140AE053A21F210A68FE#003_4


报错:
String str = '{ "isNewFlow":"1", "requestSysId":1423210758571, "requestSysName":"FMS", "taskComp":"PA011_S000000205", "taskDept":"PA011_S000033562", "taskDeptName":"集团行政组", "taskDesc":"我来测试万里通", "taskDetailList":[{"flowOwner":"PAICDOM\\ZHONGXIANGBO952", "handType":"30", "nodeDesc":"第一步审批", "seq":"1"}, {"flowOwner":"PAICDOM\\CAIJING1", "handType":"30", "nodeDesc":"第二步审批", "seq":"2"}], "taskFileList":[{"contentType":"html", "docClass":"FMSClass_url", "docName":"http://cnsz020118:5000/Page/Standard/StandardInfoForEoa.aspx?ID=a6c1657a-11a2-4355-8f8c-db36dd88d9e6", "docOldName":"测试附件链接地址", "fileSize":"50", "operator":"中向波", "requestSysId":1423210758571, "requestSysName":"FMS"}], "taskName":"万里通测试", "taskOwner":"PAICDOM\\ZHANGWENTAO446", "taskSendLeader":"审批领导", "taskSortId":"1", "taskTransactor":"ZHANGWENTAO446 650249" }';
正确:
String str = "{ 'isNewFlow':'1', 'requestSysId':1423210758571, 'requestSysName':'FMS', 'taskComp':'PA011_S000000205', 'taskDept':'PA011_S000033562', 'taskDeptName':'集团行政组', 'taskDesc':'我来测试万里通', 'taskDetailList':[{'flowOwner':'PAICDOM\\ZHONGXIANGBO952', 'handType':'30', 'nodeDesc':'第一步审批', 'seq':'1'}, {'flowOwner':'PAICDOM\\CAIJING1', 'handType':'30', 'nodeDesc':'第二步审批', 'seq':'2'}], 'taskFileList':[{'contentType':'html', 'docClass':'FMSClass_url', 'docName':'http://cnsz020118:5000/Page/Standard/StandardInfoForEoa.aspx?ID=a6c1657a-11a2-4355-8f8c-db36dd88d9e6', 'docOldName':'测试附件链接地址', 'fileSize':'50', 'operator':'中向波', 'requestSysId':1423210758571, 'requestSysName':'FMS'}], 'taskName':'万里通测试', 'taskOwner':'PAICDOM\\ZHANGWENTAO446', 'taskSendLeader':'审批领导', 'taskSortId':'1', 'taskTransactor':'ZHANGWENTAO446 650249'}";


在 C 语言,我们可以使用配置文件来存储程序参数。常见的配置文件格式有 INI、XML、JSON 等。在这里,我以 INI 文件格式为例进行说明。 首先,我们需要一个 INI 文件解析库来读取配置文件。常用的 INI 文件解析库有 libconfig、inih 等。这里我以 libconfig 为例进行说明。 假设我们有一个 INI 文件 config.ini,内容如下: ``` [database] host = localhost port = 3306 username = root password = password123 database = mydb ``` 我们可以使用 libconfig 库来读取这个配置文件,并将获取到的参数组装成一个结构体。具体代码如下: ```c #include <stdio.h> #include <stdlib.h> #include <libconfig.h> typedef struct { char *host; int port; char *username; char *password; char *database; } config_t; int main() { config_t config; config_t *config_ptr = &config; config_init(&config); if (!config_read_file(&config, "config.ini")) { fprintf(stderr, "Failed to read config file: %s\n", config_error_text(&config)); config_destroy(&config); return EXIT_FAILURE; } const char *host; if (config_lookup_string(&config, "database.host", &host)) { config_ptr->host = strdup(host); } int port; if (config_lookup_int(&config, "database.port", &port)) { config_ptr->port = port; } const char *username; if (config_lookup_string(&config, "database.username", &username)) { config_ptr->username = strdup(username); } const char *password; if (config_lookup_string(&config, "database.password", &password)) { config_ptr->password = strdup(password); } const char *database; if (config_lookup_string(&config, "database.database", &database)) { config_ptr->database = strdup(database); } printf("host: %s\n", config_ptr->host); printf("port: %d\n", config_ptr->port); printf("username: %s\n", config_ptr->username); printf("password: %s\n", config_ptr->password); printf("database: %s\n", config_ptr->database); config_destroy(&config); return EXIT_SUCCESS; } ``` 在上面的代码,我们首先定义了一个结构体 config_t,用来存储从配置文件获取到的参数。然后,我们使用 config_init 函数来初始化 config 对象,使用 config_read_file 函数来读取配置文件。接着,我们使用 config_lookup_xxx 函数来获取配置文件参数,并将其赋值给 config 对象对应的成员变量。最后,我们输出 config 对象的成员变量,以验证是否正确获取到了参数。 需要注意的是,我们在使用 config_lookup_string 函数获取字符串类型的参数时,需要使用 strdup 函数来复制参数值,否则会出现内存泄漏的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值