123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-02-15 15:26:55
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-09-28 14:22:04
- */
- #ifndef __PALYERSTATUSE_H_
- #define __PALYERSTATUSE_H_
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- #include <vector>
- #include "PlayerDeviceList.h"
- class PlayerInquire
- {
- private:
- std::string URL = "/qxsbr360xs.do";
- public:
- std::string cid;
- std::string ctype;
- std::string cname;
- std::string dtype;
- std::string did;
-
- public:
- PlayerInquire(){};
- ~PlayerInquire(){};
- void setURL(std::string url){
- this->URL = url;
- }
- std::string getUrl(){
- return this->URL;
- }
- void objectToJson(std::string& str){
- rapidjson::StringBuffer strBuf;
- rapidjson::Writer<rapidjson::StringBuffer> writer(strBuf);
- this->objectToJson(writer);
- str = strBuf.GetString();
- }
- void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
- writer.StartObject();
- writer.Key("cid");
- writer.String(cid.c_str());
- writer.Key("ctype");
- writer.String(ctype.c_str());
- writer.Key("cname");
- writer.String(cname.c_str());
- writer.Key("dtype");
- writer.String(dtype.c_str());
- writer.Key("did");
- writer.String(did.c_str());
- writer.EndObject();
- }
- };
- class PlayerStatus
- {
- private:
- std::string cid;
- std::string cmsg;
- std::string code;
- vector<PlayerDeviceList> deviceList;
-
- public:
- PlayerStatus() {};
- ~PlayerStatus() {};
- /**
- * @description: json转换为对象
- * @param {string&} json
- * @return {*}
- */
- bool jsonToObject(const std::string& json){
- rapidjson::Document doc;
- doc.Parse(json.c_str());
- if(!doc.IsObject()){
- return false;
- }
- // get members
- const auto end = doc.MemberEnd();
- if(end == doc.FindMember("cid") || !doc["cid"].IsString()){
- return false;
- }
- else{
- cid = doc["cid"].GetString();
- }
- if(end == doc.FindMember("cmsg") || !doc["cmsg"].IsString()){
- return false;
- }
- else{
- cmsg = doc["cmsg"].GetString();
- }
- if(end == doc.FindMember("code") || !doc["code"].IsString()){
- return false;
- }
- else{
- code = doc["code"].GetString();
- }
- if(end == doc.FindMember("deviceList") || !doc["deviceList"].IsArray()){
- return false;
- }
- else{
- const rapidjson::Value& objs = doc["deviceList"];
- for(size_t i = 0; i < objs.Size(); i++){
- const rapidjson::Value& obj = objs[i];
- PlayerDeviceList playerDevice;
- if(!playerDevice.jsonToObject(obj)){
- return false;
- }
- deviceList.push_back(playerDevice);
- }
- }
-
- return true;
- }
- };
- #endif
|