【发布时间】:2021-10-02 12:04:13
【问题描述】:
void exp::example(std::string &a, std::string &b)
{
if (m_root.isObject() && m_root.isMember(a))
{
if (m_root[a].isMember(b))
{
m_root[a].append(b);
}
}
else
{
m_root[a] = Json::arrayValue;
m_root[a].append(b);
}
}
(m_root 在 hpp 中定义)
当我运行此代码时,出现逻辑错误:
在 Json::Value::find(key, end, found) 中:需要 objectValue 或 nullValue。
我发现如果出现以下情况,我会收到此错误:
if (m_root[a].isMember(b))
我不明白为什么会出现这个错误,我在他上面的 if 中使用了相同的函数,我没有得到这个错误。
P.S 该函数一直在工作,直到它进入嵌套的 if,例如:
| a | b | m_root |
|---|---|---|
| "hey" | "a1" | {"hey":["a1"]} |
| "bye" | "a2" | {"hey":["a1"], "bye":["b1"]} |
| "cye" | "a3" | {"hey":["a1"], "bye":["b1"], "cye":["a3"]} |
| "hey" | "a4" | error: in Json::Value::find(key, end, found): requires objectValue or nullValue |
我只在第 4 次通话中收到错误。 感谢您的帮助!
【问题讨论】: