field_map is not a member of web::json::Value

Apr 16, 2014 at 4:37 PM
I just installed the C++ REST SDK today. And try to compile an example code, however, it is reporting 'field_map is not a member of web::json::value error.

The following are all the libraries I included and namespaces used:

include <cpprest/http_listener.h>

include <cpprest/json.h>

pragma comment(lib, "cpprest110_1_1")

using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;

include <iostream>

include <map>

include <set>

include <string>

using namespace std;

any one knows the reason?
Apr 16, 2014 at 5:32 PM
Hi qfliu,

In version 2.0.0 and later of the C++ Rest SDK we removed the typedef 'field_map'. What version specifically are you trying to use? It appears you are trying to link with 1.1. I'd recommend you update the our latest release 2.0.1 as it contains many bug fixes and improvements. If you provide your full code I can take a look, but I think it is unlikely there is an issue here.

Steve
Marked as answer by roschuma on 4/17/2014 at 9:14 AM
Apr 16, 2014 at 6:36 PM
Hi,
Thanks for the quick response.
I just got the newest version of Rest SDK. I was looking at an example for version 1.1.  That was my bad.
Can you point me to an simple example for using the 2.0.1 version. I cannot seem to find one online.

Thanks.
Apr 16, 2014 at 6:42 PM
Hi qfliu,

I'd recommend you get started by taking a look at our beginning http client tutorial here. After that I'd look around some of the pages on our documentation tab, specifically the each of the features in the 'Feature Overview' matrix contain short overviews and code snippets. For example here is the one for our JSON library.

Steve
Sep 18, 2014 at 11:23 AM
Edited Sep 18, 2014 at 1:12 PM
@SteveGates, what is used instead of field_maps?

I have to get my code working. But can't, because of this field_map

int _tmain(int argc, _TCHAR* argv[])
{
                 listener.support(methods::POST, handle_post);
}

void handle_get(http_request request)
{   
    //TRACE(L"\nhandle GET\n");    
    
    json::value::field_map answer;    

    for(auto const & p : dictionary)   
    {      
        answer.push_back(make_pair(json::value(p.first), json::value(p.second)));   
    }    
    request.reply(status_codes::OK, json::value::object(answer));
}
Sep 18, 2014 at 5:28 PM
Hi maverick786us,

std::vector of pair of string_t, json::value is used instead. Recommend you take a look at the JSON reference documentation.

Steve
Mar 3, 2015 at 1:07 PM
Edited Mar 3, 2015 at 1:16 PM
I have changed the json::value::field_map answer; to std::vector< std::pair< utility::string_t, json::value > > answer;, but I get the undefined reference to `web::json::value::object(std::vector<std::pair<std::string, web::json::value>, std::allocator<std::pair<std::string, web::json::value> > >, bool)' error
Why does it convert utility::string_t to std::string?
Mar 3, 2015 at 5:49 PM
Hi opreanstefan,

As stated in this thread, the field_map API not longer exists in the library. I can't tell from your mention about an undefined reference. Can you please post the code and the full error log?

Steve