欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

拼接JSON字符串

发布时间:2025/6/15 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 拼接JSON字符串 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

               传输数据时经常要用到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]$


注意 \ 的使用,它起到换行的作用,还有 " 需要进行转义。


总结

以上是生活随笔为你收集整理的拼接JSON字符串的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。