ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Am not so sure what you want to do, but I can tell you C++ and Json... hummm
you can use a lib called rapid json and generate the json you need appending key-values as it were a dictionary
here an example:
#include <iostream>
#include <string>
#include <rapidjson\document.h>
#include <rapidjson\writer.h>
#include <rapidjson\stringbuffer.h>
void output(const rapidjson::Document& document)
{
std::string strOp = document["op"].GetString();
std::string ret = "{\"op\":\"" + strOp;
std::string strTopic = document["topic"].GetString();
ret += "\", \"topic\":\"" + strTopic;
std::string strType = document["type"].GetString();
ret += "\", \"type\":\"" + strType + "\"}";
std::cout << "json" << std::endl;
std::cout << ret << std::endl;
//{ "op": "subscribe", "topic" : "/cmd_vel", "type" : "geometry_msgs/Twist" }
}
int main(int argC, char** argV)
{
std::cout << "ROS" << std::endl;
rapidjson::Document fromScratch;
fromScratch.SetObject();
rapidjson::Document::AllocatorType& allocator = fromScratch.GetAllocator();
fromScratch.AddMember("op", "subscribe", allocator);
fromScratch.AddMember("topic", "/cmd_vel", allocator);
fromScratch.AddMember("type", "geometry_msgs/Twist", allocator);
output(fromScratch);
getchar();
return 0;
}
The output will look like: