ApiResult.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ApiResult
  9. {
  10. public:
  11. int status;
  12. std::string msg;
  13. std::string result;
  14. std::string attr1;
  15. std::string attr2;
  16. std::string attr3;
  17. public:
  18. ApiResult() {}
  19. ~ApiResult() {}
  20. /**
  21. * @description: 对象转为json
  22. * @param {rapidjson::Writer<rapidjson::StringBuffer>& writer}
  23. * @return {*}
  24. */
  25. void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
  26. writer.StartObject();
  27. writer.Key("status");
  28. writer.Int(status);
  29. writer.Key("msg");
  30. writer.String(msg.c_str());
  31. writer.Key("result");
  32. writer.String(result.c_str());
  33. writer.Key("attr1");
  34. writer.String(attr1.c_str());
  35. writer.Key("attr2");
  36. writer.String(attr2.c_str());
  37. writer.Key("attr3");
  38. writer.String(attr3.c_str());
  39. writer.EndObject();
  40. }
  41. /**
  42. * @description: json转换为对象
  43. * @param {*}
  44. * @return {*}
  45. */
  46. bool JsonToObject(){
  47. return true;
  48. }
  49. };