使用 JsonCPP 创建 Json 消息
Create Json Message using JsonCpp
我正在尝试使用 Jsoncpp 创建 Json 消息。我已经做了如下:
#include <string>
#include <iostream>
#include <sstream>
#include <json/json.h>
int main()
{
std::string Value = "5.17e9";
std::string Type = "TX";
std::string Parameter = "Frequency";
Json::Value root;
root.append("Type");
root.append("Parameter");
root.append("Value");
root["Type"] = Type;
root["Parameter"] = Parameter;
root["Value"] = Value;
Json::FastWriter fastwriter;
std::string message = fastwriter.write(root);
std::cout<<message<<std::endl;
return 0;
}
使用以下命令行编译此代码:
g++ -o clients clients.cpp -ljsoncpp -lzmq
发生此类错误:
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x1d9): undefined reference to `Json::Value::operator=(Json::Value)'
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x224): undefined reference to `Json::Value::operator=(Json::Value)'
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x26c): undefined reference to `Json::Value::operator=(Json::Value)'
collect2: error: ld returned 1 exit status
我的代码有什么问题?
我不确定链接错误,但是代码存在问题,在编译器中可能会以不同的方式处理。这对我来说是一个运行时错误。
Json::Value root;
root.append("Type"); // makes root into arrayValue
root["Type"] = Type; // accesses root as an objectValue
// triggers assert in Json::Value::resolveReference
这就是我的做法:
Json::Value root;
root["Type"] = Type;
相关文章:
- boost::进程间消息队列引发错误
- 在c++中使用nlohmann从类到json的转换
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- C++json插入数组
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- nlohmann-json将一个数组插入到另一个数组中
- 如何使用curlpp通过POST方法上传文件和json数据
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- JSON转换为nlohmann JSON-lib中的结构数组
- NLOHMANN 的 JSON 库将数组转换为结构向量
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 如何通过参数抛出错误消息
- 如何在 nlohmann 的 json 库中获取数组长度?
- 从服务器传输到客户端的消息不会出现
- C++ CURL Json 请求不和谐 API 以发布消息
- CPPRestSDK(casablanca)从传入的WebSocket消息中提取JSON(格式错误的令牌)
- 使用 JsonCPP 创建 Json 消息
- 使用Boost Json读取JSON消息
- 无效输入会导致多语言 JSON 消息传递系统中的身份验证绕过