123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #pragma once
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- using namespace std;
- class SendBird
- {
- private:
- public:
- string birdImageBase64;
- int birdNum;
- string birdType;
- int degree;
- string deviceUuid;
- string heightRange;
- string remark;
- int repeStatus;
- string warningTime;
- string attr4;
- string attr5;
- SendBird(){};
- ~SendBird(){};
- 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("birdImageBase64");
- writer.String(birdImageBase64.c_str());
- writer.Key("birdNum");
- writer.Int(birdNum);
- writer.Key("birdType");
- writer.String(birdType.c_str());
- writer.Key("degree");
- writer.Int(degree);
- writer.Key("deviceUuid");
- writer.String(deviceUuid.c_str());
- writer.Key("heightRange");
- writer.String(heightRange.c_str());
- writer.Key("remark");
- writer.String(remark.c_str());
- writer.Key("repeStatus");
- writer.Int(repeStatus);
- writer.Key("warningTime");
- writer.String(warningTime.c_str());
- writer.Key("attr4");
- writer.String(attr4.c_str());
- writer.Key("attr5");
- writer.String(attr5.c_str());
-
- writer.EndObject();
- }
- 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("birdImageBase64") || !doc["birdImageBase64"].IsString()) {
- return false;
- }else{
- birdImageBase64 = doc["birdImageBase64"].GetString();
- }
- if (end == doc.FindMember("birdNum") || !doc["birdNum"].IsInt()) {
- return false;
- } else {
- birdNum = doc["birdNum"].GetInt();
- }
- if(end == doc.FindMember("birdType") || !doc["birdType"].IsString()) {
- return false;
- }else{
- birdType = doc["birdType"].GetString();
- }
-
- if (end == doc.FindMember("degree") || !doc["degree"].IsInt()) {
- return false;
- } else {
- degree = doc["degree"].GetInt();
- }
- if(end == doc.FindMember("deviceUuid") || !doc["deviceUuid"].IsString()) {
- return false;
- }else{
- deviceUuid = doc["deviceUuid"].GetString();
- }
- if(end == doc.FindMember("heightRange") || !doc["heightRange"].IsString()) {
- return false;
- }else{
- heightRange = doc["heightRange"].GetString();
- }
- if(end == doc.FindMember("repeStatus") || !doc["repeStatus"].IsInt()) {
- return false;
- }else{
- repeStatus = doc["repeStatus"].GetInt();
- }
- if(end == doc.FindMember("warningTime") || !doc["warningTime"].IsString()) {
- return false;
- }else{
- warningTime = doc["warningTime"].GetString();
- }
- return true;
- }
- };
|