快速JSON如何使用字符串变量查询对象
RapidJSON how to query an object using a string variable
当我尝试使用字符串变量查询对象时,我收到错误,但当我直接使用字符串时则不然。
杰森: {"x": "hello"}
这有效:
std::cout << document["x"].GetString();
这不起作用:
std::string s = "x";
std::cout << document[s].GetString();
我收到此错误:
error: no viable overloaded operator[] for type 'rapidjson::Document'
(aka 'GenericDocument<UTF8<> >')
std::cout << document[s].GetString();
~~~~~^~
note: candidate function not viable: no known conversion from 'std::string'
(aka 'basic_string<char, char_traits<char>, allocator<char> >') to 'SizeType'
(aka 'unsigned int') for 1st argument
我做错了什么?
尝试
std::cout << document[s.c_str()].GetString();
似乎运算符不是针对 std::string 重载,而是针对 C 字符串。
(c_str成员函数的参考)
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- 结构变量查询
- 快速JSON如何使用字符串变量查询对象
- 带变量的 SQL 查询
- 如何在C 中的查询中传递变量
- 将变量插入到 SQLite 查询
- 查询特定变量的对齐方式
- 在MSSQL查询中使用C++变量
- 在 c++ 中使用"char*"变量进行查询
- 查询全局变量的初始化
- 如何使用本地变量作为MySQL查询的一部分(Qt c++)
- 查询类的静态成员变量
- 用查询中的变量替换表名
- c++和MySQL -如何在我的查询中包含变量
- 如何在c++中执行SQL查询来定义变量
- 在C语言中使用查询变量的SQL语句