Mysql c++ json 字符串存在换行符的话无法插入到json,但是在Workbench存在\n右可以插入,
//读取文本的内容
ptr = evbuffer_search(inbuf, postfix.c_str(), postfix.length(), NULL); //查找文件分隔符
if (ptr.pos != -1) {
temp_char = new char[ptr.pos];
if (evbuffer_remove(inbuf, temp_char, ptr.pos) != -1) {
temp_char = trim(temp_char); //清除首尾换行符
//把temp_char里面的换行符 或者 \t替换成 \\t;
cout << "用户发送的文本内容是:" << temp_char << endl;
WriteFile.Key("Content"); //添加内容
WriteFile.String(temp_char);
cout << "添加到WriteFile之后的内容是" << endl;
cout << WriteBuf.GetString() << endl;
}
}
下面是程序执行的输出:
用户发送的文本内容是:测试1行
测试2行
测试3行
f-8
添加到WriteFile之后的内容是
{"type":"string","Content":"测试1行\n\n测试2行\n\n测试3行\r\nf-8"
文件夹:/GongXiang/Assest/1/111/不存在,开始创建
文件夹: /GongXiang/Assest/1/111/创建成功
Invalid JSON text: "Invalid escape character in string." at position 38 in value for column 'PostProperty.PostContentJson'.更新帖子的数量失败了,错误原因是: 行号为:468 文件名为: ./thread_task.cpp