json用于传递网络请求确实方便,有些错误也是很奇怪。
nlohmann::json name;
name["Name"] = m_name;
cout<<"m_name is ["<<m_name<<"]"<<endl;
cout<<"name is ["<<name<<"]"<<endl;
上面的代码输出:
比预期多了一个\u0000,很烦。找了c++相关文章没有答案,只好自己动手规避一下:
nlohmann::json name;
name["Name"] = m_name.substr(0,m_name.length()-1);
cout<<"m_name is ["<<m_name<<"]"<<endl;
cout<<"name is ["<<name<<"]"<<endl;
修改后输出: