json cpprestsdk复制json对象-解析函数未进行深层复制

时间:2018-09-12 23:11:35

标签: json object copy cpprest-sdk

我在使用json cpprestsdk保存JSON响应时遇到问题,因此我无法将其传递回调用函数。 parse()函数似乎执行的是浅表副本,而不是深表副本。有人可以帮我提供我应该使用的方法来对返回的结果进行深入复制的方法吗?

谢谢。

functionA()
{

   web::json::value myJsonObjSv;

   http_client client(L"http://url.com:8080/getdata");

   return client.request(methods::GET).then([](http_response response) -> pplx::task<json::value> {

       if(response.status_code() == status_codes::OK) {
           return response.extract_json();
       }

   return pplx::task_from_result(json::value()); }).then([&myJsonObjSv](pplx::task<json::value> previousTask) {
        try {
             // capture json response to json_resp
             json::value const resp = previousTask.get();

             // Now save the JSON object to return from this function
             myJsonObjSv = json::value::parse(resp.serialize());

             // This statement displays the contents of myJsonObjSv to be the same as resp
             wcout << "myJsonObjSv[" myJsonObjSv.serialize() << "]" << endl;
         }
        catch( const http_exception& e) {
             // print error
         }
    });

    // This statement to display the contents of myJsonObjSv crashes since there was a shallow copy made rather than a deep copy
    wcout << "myJsonObjSv[" myJsonObjSv.serialize() << "]" << endl;

}

0 个答案:

没有答案