浏览代码

#IQRV #comment [Restful] 重构结构体内容2

gifur 3 年之前
父节点
当前提交
b7cc7e9098
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      Module/include/CommEntityRestful.hpp

+ 11 - 0
Module/include/CommEntityRestful.hpp

@@ -32,6 +32,17 @@ static bool ExtractDataFromDebranchResponse(const std::string& content, T& outDa
     return (!GetJsonRootObject(rawRoot, content)) ? false : Json2Object(outDataStruct, rawRoot["data"]);
 }
 
+template <typename T>
+static bool FulfillRequestJsonBody(HttpClientRequestConfig* pConfig, const T& dataStruct)
+{
+    std::string jsonValue;
+    if (Object2Json(jsonValue, dataStruct)) {
+        pConfig.SetJsonBody(jsonValue);
+        return true;
+    }
+    return false;
+}
+
 } //Restful
 
 } //Module