12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #ifndef __FINDDEVMSG_H_
- #define __FINDDEVMSG_H_
- #include <iostream>
- #include <vector>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- using namespace std;
- class findDevMsg
- {
- public:
- std::string requestId;
- std::string ServerIP;
- int ServerPort;
- std::string DockerAddress;
- int DockerPort;
- std::string attr1;
- std::string attr2;
- std::string attr3;
- public:
- findDevMsg(){}
- ~findDevMsg(){}
- /**
- * @description: json转换为object
- * @param {string&} json
- * @return {*}
- */
- bool JsonToObject(std::string& json){
- rapidjson::Document doc;
- if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
- return false;
- }
- // get members
- const auto end = doc.MemberEnd();
- // json_type
- // if(end == doc.FindMember("requestId") || !doc["requestId"].IsString()) {
- // return false;
- // }else{
- // requestId = doc["requestId"].GetString();
- // }
- if(end == doc.FindMember("ServerIP") || !doc["ServerIP"].IsString()) {
- return false;
- }else{
- ServerIP = doc["ServerIP"].GetString();
- }
-
- if(end == doc.FindMember("ServerPort") || !doc["ServerPort"].IsInt()) {
- return false;
- }else{
- ServerPort = doc["ServerPort"].GetInt();
- }
- if(end == doc.FindMember("DockerAddress") || !doc["DockerAddress"].IsString()) {
- return false;
- }else{
- DockerAddress = doc["DockerAddress"].GetString();
- }
- if(end == doc.FindMember("DockerPort") || !doc["DockerPort"].IsInt()) {
- return false;
- }else{
- DockerPort = doc["DockerPort"].GetInt();
- }
- if(end != doc.FindMember("attr1") && doc["attr1"].IsString()) {
- attr1 = doc["attr1"].GetString();
- }
- if(end != doc.FindMember("attr2") && doc["attr2"].IsString()) {
- attr1 = doc["attr2"].GetString();
- }
- if(end != doc.FindMember("attr3") && doc["attr3"].IsString()) {
- attr3 = doc["attr3"].GetString();
- }
-
- return true;
- }
- };
- #endif
|