I am fairly new to C++ and I apologise beforehand if you find this very easy.
I have the following files POST1.h
#ifndef POST1_HH
#define POST1_HH
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
using namespace std ;
using boost::property_tree::ptree;
using boost::property_tree::read_json;
using boost::property_tree::write_json;
using boost::property_tree::basic_ptree;
#include "DBAccess2.h"
class POST1
{
public:
string TokenNo;
string CommandStatus;
string CommandID;
string CPUID;
string ISEncrypted;
string JSON_Cmnd_String;
void POST_Device_Status(sqliteDB & DB_OBJ);
};
#endif
Below is POST1.cpp
#include <iostream>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "DBAccess2.h"
#include "POST1.h"
using namespace std ;
using boost::property_tree::ptree;
using boost::property_tree::read_json;
using boost::property_tree::write_json;
using boost::property_tree::basic_ptree;
void POST1::POST_Device_Status(sqliteDB & DB_OBJ)
{
POST1 POST_OBJ;
POST_OBJ.TokenNo = "1122";
POST_OBJ.CommandStatus = "0";
POST_OBJ.CommandID = "00";
POST_OBJ.CPUID = "A1234B1234";
POST_OBJ.ISEncrypted = "0";
POST_OBJ.JSON_Cmnd_String = DB_OBJ.dump(DB_OBJ);
}
NOTE:-
(1) sqliteDB is another class declared in a .cpp file.
(2) the output of function dump() is a json string. this get stored into JSON_Cmnd_string.
So, I want to convert the class object into JSON string, How can I do that ? Do I have to first put these object into a container (like vector or list) and then write it into JSON?