1. 方法一
Convert raw strings to escaped C/C++ string literals
https://github.com/jhandley/escaper
我们在生成json串时经常会把原始串转义一下,如
{"repoID":1234,"name":"YYModel","user":{"uid":5678,"name":"ibireme"}}
在程序当中我们生成:
"{\"repoID\":1234,\"name\":\"YYModel\",\"user\":{\"uid\":5678,\"name\":\"ibireme\"}}"
在oc当中也是这样用的,这个小工具可以进行转换,操作也很方便。
2. 方法二:
c++ 11 的raw strings 实现了这个功能,现在我发现在c11里边还没有,没看到代码是怎么实现的,但c++实现了:
std::string path = R"( {"repoID":1234,"name":"YYModel","user":{"uid":5678,"name":"ibireme"}} )";
就可以了,c++ 先进的,c没有跟上啊。