使用CPPREST-SDK将std::vector转换为JSON 目前我正在研究C++项目,使用CPPRSTSDK(A.K.CasabrANCA)编写API的服务器端。 cpprestsdk库中已经实现了int、double等序列化值
我现在想问一下,是否有任何方法可以在客户端将使用CPPREST-SDK将std::vector转换为JSON 目前我正在研究C++项目,使用CPPRSTSDK(A.K.CasabrANCA)编写API的服务器端。 cpprestsdk库中已经实现了int、double等序列化值,c++,json,cpprest-sdk,C++,Json,Cpprest Sdk,我现在想问一下,是否有任何方法可以在客户端将std::vector序列化为json::value,进行重新请求,然后在服务器上对其进行反序列化? 比如: http_client client(U("http://localhost")); json::value jsonVector(std::vector); make_task_request(client, methods::POST, jsonVector) 提前感谢您所做的一切 向量序列化: std::
std::vector
序列化为json::value
,进行重新请求,然后在服务器上对其进行反序列化?比如:
http_client client(U("http://localhost"));
json::value jsonVector(std::vector);
make_task_request(client, methods::POST, jsonVector)
提前感谢您所做的一切 向量序列化:
std::vector<int> someVector;
web::json::value json;
std::vector<value> array;
if (someVectory.size()) {
for (auto num : someVector) {
array.push_back(value(num));
}
json["yourKey"] = value::array(array);
}
还可以通过迭代器使用std::vector的构造函数反序列化为std::vector,即:std::vector(array.cbegin(),array.cend());。
std::vector<int> intVector;
for (auto it=array.cbegin();it!=array.cend();++it) {
intVector.push_back(it->as_integer());
}