c++ - json 序列化 C++

标签 c++ json

我有此 C++ 代码,但在对其进行 json 序列化时遇到问题。

 string uInput;
 string const& retInput;
 while(!std::cin.eof()) {
   getline(cin, uInput);
   JSONExample source; //JSON enabled class from jsonserialize.h
   source.text = uInput;
   //create JSON from producer
   std::string json = JSON::producer<JSONExample>::convert(source); //string -> returns {"JSONExample":{"text":"hi"}}
   //then create new instance from a consumer...
   JSONExample sink = JSON::consumer<JSONExample>::convert(json);
   //retInput = serialize(sink);
   // Json::FastWriter fastWriter;
   // retInput = fastWriter.write(uInput);
   retInput = static_cast<string const&>(uInput);
   pubnub::futres fr_2 = pb_2.publish(chan, retInput);
   cout << "user input as json which should be published is " << retInput<< std::endl;

最佳答案

 while(!cin.eof()) {
   getline(cin, uInput);
   newInput = "\"\\\""; 
   newInput += uInput;
   newInput += "\\\"\""; 

这段代码不是输入“hi”这样的消息,而是接受“hi”并执行此操作。

关于c++ - json 序列化 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123771/

相关文章:

c++ - 从派生类中删除虚函数

c++ - 我是否需要实现 FileNotFoundError 异常?

c++ - 基类使用父类定义的类型

javascript - 使用 Ajax 将元素附加到 Json 响应

json - redux 存储中的大数据

ruby - 如何在 ruby​​ on rails 中使用 Ajax?

c++ - 使用 C++ 的 RGB 到 CMY 颜色模型

C++11 constexpr 可变逻辑表达式

json - JSON 有哪些好的 CLI 工具?

json - 我可以在 JSON 部署模板之外调用 ARM 模板函数吗?