12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #pragma once
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- using namespace std;
- class ApiResult
- {
- public:
- int status;
- std::string msg;
- std::string result;
- std::string attr1;
- std::string attr2;
- std::string attr3;
- public:
- ApiResult() {}
- ~ApiResult() {}
- /**
- * @description: 对象转为json
- * @param {rapidjson::Writer<rapidjson::StringBuffer>& writer}
- * @return {*}
- */
- void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
- writer.StartObject();
- writer.Key("status");
- writer.Int(status);
- writer.Key("msg");
- writer.String(msg.c_str());
- writer.Key("result");
- writer.String(result.c_str());
- writer.Key("attr1");
- writer.String(attr1.c_str());
- writer.Key("attr2");
- writer.String(attr2.c_str());
- writer.Key("attr3");
- writer.String(attr3.c_str());
- writer.EndObject();
- }
- /**
- * @description: json转换为对象
- * @param {*}
- * @return {*}
- */
- bool JsonToObject(){
- return true;
- }
- };
|