从 Wt::Http::Request&request 获取 json
Get json from Wt::Http::Request& request
我的json请求有问题:(我有class
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-response.
您将需要解析来自
提供的输入流的数据std::istream & Wt::Http::Request::in ( ) const
https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Http_1_1Request.html a768a65ceb3c0bf013b57c3de04b19041
应该是原始的json文本
Wt中有一个内置的JSON解析器。我这样使用它:
Wt::Json::Object bodyContent;
try
{
Wt::Json::parse(fromIstream(request.in()), bodyContent);
}
catch(std::exception e)
{
...
}
其中fromisam如下:
std::string fromIstream(std::istream &stream)
{
std::istreambuf_iterator<char> eos;
return std::string(std::istreambuf_iterator<char>(stream), eos);
}
请记住,Wt::Json::parse()将在格式错误的情况下抛出异常。希望能有所帮助!
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 从 Wt::Http::Request&request 获取 json