我对json请求有问题:(我有课。)
class ForumCreate : public Wt::WResource 和功能
virtual void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)request.contentType()是application/json。我怎样才能从请求中得到json?
也许我该用点别的东西让json?任务:用户在静态url上发送带有json的http请求。我需要分析json文件并发送json响应。
发布于 2016-10-11 23:06:34
您需要解析输入流中的数据。
std::istream & Wt::Http::Request::in ( ) const1Request.html#a768a65ceb3c0bf013b57c3de04b19041
它应该是原始的json文本。
发布于 2017-05-09 15:05:24
Wt中有一个内置的JSON解析器。我就是这样用的:
Wt::Json::Object bodyContent;
try
{
Wt::Json::parse(fromIstream(request.in()), bodyContent);
}
catch(std::exception e)
{
...
}其中fromIstream如下:
std::string fromIstream(std::istream &stream)
{
std::istreambuf_iterator<char> eos;
return std::string(std::istreambuf_iterator<char>(stream), eos);
}请记住,在格式错误的输入情况下,Wt::Json::parse()将抛出异常。希望能帮上忙!
https://stackoverflow.com/questions/39987974
复制相似问题