123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #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;
- doc.Parse(json.c_str());
- if(!doc.IsObject()){
- 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
|