带有restclient cpp的JSON属性树
JSON property trees with restclient-cpp
我正在尝试使用Boost对JSON数组进行一些计算,我的问题如下:
我如何进行rest调用(使用类似rest客户端cpp的东西)来用JSON数据填充Ptree,而不是使用文件。
以下是我目前所拥有的:
namespace pt = boost::property_tree;
pt::ptree root;
pt::read_json("filename.json", root);
我想用通过GET请求引入的json替换"filename.json"。以下是使用"rest client cpp"时的rest调用示例
RestClient::response r = RestClient::get("http://urlhere.com");
有什么想法或建议吗?
您可以使用接收istream
的read_json版本。您应该创建std::istringstream并将响应的内容存储在其中。
RestClient::response r = RestClient::get("http://urlhere.com");
std::istreamstream stream(r.body);
pt::ptree root;
pt::read_json(stream, root);
您可以使用std::istream
而不是文件名来调用read_json。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 在c++中使用nlohmann从类到json的转换
- C++概念:如何使用'concept'检查模板化结构的属性?
- C++json插入数组
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- nlohmann-json将一个数组插入到另一个数组中
- 如何在 C++ 中使用提升属性树从 JSON 文件中读取对象数组
- 如何使用 boost 属性树来解析 boost 中 json 字符串中的数组中的元素?
- boost属性树解析json后无法检索记录
- Boost属性树Json读取包含LPWSTR的文件
- 如何将标准::字符串格式的 JSON 解码为 Boost 属性树
- 获取json属性duktape
- 带有restclient cpp的JSON属性树
- 从json文件构造boost属性树的性能非常差
- Boost Library函数将JSON格式的属性树转换为点分隔的字符串
- 使用boost属性树迭代json属性键和值
- Boost属性树不能在一个文件中读取多个json数据
- 实体-属性-值模式或数据库中的JSON
- Boost属性树:我的转义序列在JSON字符串中去了哪里
- 用boost属性树解析JSON