HepuTarget2Re.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <iostream>
  3. #include <rapidjson/document.h>
  4. #include <rapidjson/rapidjson.h>
  5. #include <rapidjson/stringbuffer.h>
  6. #include <rapidjson/writer.h>
  7. using namespace std;
  8. class HepuTarget2Re
  9. {
  10. private:
  11. public:
  12. const string cmd = "ivpClientTracking";
  13. int ackvalue;
  14. int channelid;
  15. bool bTracking;
  16. HepuTarget2Re(){};
  17. ~HepuTarget2Re(){};
  18. bool jsonToObject(string& json){
  19. rapidjson::Document doc;
  20. doc.Parse(json.c_str());
  21. if(!doc.IsObject()){
  22. return false;
  23. }
  24. const auto end = doc.MemberEnd();
  25. if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){
  26. return false;
  27. }else{
  28. if(cmd != doc["cmd"].GetString())
  29. return false;
  30. }
  31. if(end == doc.FindMember("param") || !doc["param"].IsObject()) {
  32. return false;
  33. }else{
  34. const rapidjson::Value& object = doc["param"];
  35. if(end == object.FindMember("ackvalue") || !object["ackvalue"].IsInt()) {
  36. return false;
  37. }else{
  38. ackvalue = object["ackvalue"].GetInt();
  39. }
  40. }
  41. return true;
  42. }
  43. };