Sim*_*Guy 1 c++ json getjson casablanca visual-studio-2015
我是C++ REST('Casablanca')的新手.我在这里阅读教程.之后,我从那里拿了一个示例代码并尝试在我的机器上运行它.
下面是代码
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;
}
Run Code Online (Sandbox Code Playgroud)
在此代码中,我收到如下错误
我检查了头文件json.h,找不到名为Please help的成员(class/struct)field_map
我认为下面的代码可以替换你的代码,应该编译最新的稳定版本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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1839 次 |
| 最近记录: |