You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
747 B
36 lines
747 B
#include "JsonCoversion.h"
|
|
|
|
JsonCoversion::JsonCoversion()
|
|
{
|
|
//ctor
|
|
}
|
|
|
|
JsonCoversion::~JsonCoversion()
|
|
{
|
|
//dtor
|
|
}
|
|
string JsonCoversion::toJson()
|
|
{
|
|
toJsonValue();
|
|
|
|
std::unique_ptr<Json::StreamWriter> jsonWriter(writerBuilder.newStreamWriter());
|
|
std::ostringstream os;
|
|
std::string jsonStr;
|
|
jsonWriter->write(root,&os);
|
|
jsonStr = os.str();
|
|
return jsonStr;
|
|
}
|
|
|
|
void JsonCoversion::toObject(string & strBuf)
|
|
{
|
|
std::unique_ptr<Json::CharReader> const jsonReader(readerBuilder.newCharReader());
|
|
|
|
JSONCPP_STRING errs;
|
|
bool res = jsonReader->parse(strBuf.c_str(), strBuf.c_str()+strBuf.length(), &root, &errs);
|
|
if (!res || !errs.empty())
|
|
{
|
|
std::cout << "parseJson err. " << errs << std::endl;
|
|
}
|
|
toObjectFromValue(root);
|
|
}
|