1234567891011121314151617181920212223242526 |
- #include "../include/jsonhandler.h"
- #include "../include/cmdmanager.h"
- using namespace std;
- // This method gets a string and tries to read it as Json
- // If it fails to do so, return and do nothing, else handle the content
- void JsonHandler::parseJSON(string buffer) {
- Json::Value root;
- Json::CharReaderBuilder builder;
- Json::CharReader *reader = builder.newCharReader();
- string jsonError;
- // Try to parse the string as Json and store the result of the pasring in a
- // boolean
- bool parsingSuccessful = reader->parse(buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
- // If the string is not correct Json, return
- if (!parsingSuccessful) {
- return;
- }
- string cmd = root["command"].asString();
- CmdManager::executeCmd(cmd, root);
- }
|