当前位置:
首页 >
拼接JSON字符串
发布时间:2025/6/15
48
豆豆
传输数据时经常要用到JSON格式,拼接JSON字符串是常用的事,这里记录一下,直接看代码吧。
[mapan@localhost unixNetwork]$ cat test.cpp #include<stdio.h> #include<string.h> void func(char test1[],char test2[],char test3[]) {char test[100];sprintf(test,"{\r\n meida_code:\"%s\",\\r\n app_id:\"%s\",\\r\n user_id:\"%s\",\\r\n}",test1,test2,test3);printf("%s\n",test); }int main() { char str1[]="1";char str2[]="2";char str3[]="3";func(str1,str2,str3);return 0; } [mapan@localhost unixNetwork]$ g++ test.cpp [mapan@localhost unixNetwork]$ ./a.out {meida_code:"1", app_id:"2", user_id:"3", } [mapan@localhost unixNetwork]$
总结
- 上一篇: shutdown函数和FIN_WAIT2
- 下一篇: cJSON库源码分析