1

C++ REST (「カサブランカ」) は初めてです。ここでチュートリアルを読みました。その後、そこからサンプル コードを取得し、自分のマシンで実行しようとしました。

以下はコードです

std::map<utility::string_t, utility::string_t> dictionary;

void handle_get(http_request request)
{
    TRACE(L"\nhandle GET\n");

    web::json::value::field_map answer;

    for (auto const & p : dictionary)
    {
        answer.push_back(std::make_pair(json::value(p.first), json::value(p.second)));
    }

    request.reply(status_codes::OK, json::value::object(answer));
}

int main()
{
    http_listener listener(L"http://127.0.0.1:8080/stockData");

    listener.support(methods::GET, handle_get);

    return 0;
}

このコードでは、以下のようなエラーが発生しています

ここに画像の説明を入力

ヘッダー ファイルを確認したところ、Please helpjson.hとい​​う名前のメンバー (クラス/構造体) が見つかりませんでしたfield_map

4

1 に答える 1

6

以下のコードはあなたのコードを置き換えることができ、最新の安定バージョン cpprestsdk v2.8.0 をコンパイルする必要があると思います

std::map<utility::string_t, utility::string_t> dictionary;

void handle_get(http_request request)
{
    TRACE(L"\nhandle GET\n");

    json::value obj;
    for ( auto const & p : dictionary )
    {
        obj[p.first] = json::value::string(p.second);
    }

    // this is just for debugging
    utility::stringstream_t stream;
    obj.serialize(stream);
    std::wcout << stream.str();

    request.reply( status_codes::OK, obj);
}
于 2016-08-08T12:46:18.483 に答える