gpt4 book ai didi

c++ - 使用 jsoncpp 创建空的 json 数组

转载 作者:IT老高 更新时间:2023-10-28 22:16:35 31 4
gpt4 key购买 nike

我有以下代码:

void MyClass::myMethod(Json::Value& jsonValue_ref)
{
for (int i = 0; i <= m_stringList.size(); i++)
{
if (m_boolMarkerList[i])
{
jsonValue_ref.append(stringList[i]);
}
}
}

void MyClass::myOuterMethod()
{
Json::Value jsonRoot;
Json::Value jsonValue;

myMethod(jsonValue);

jsonRoot["somevalue"] = jsonValue;
Json::StyledWriter writer;
std::string out_string = writer.write(jsonRoot);
}

如果 m_boolMarkerList 中的所有标记均为 false,则 out_string{ "somevalue": null },但我希望它是空数组:{ "somevalue": [ ] }

有人知道如何实现吗?

非常感谢!

最佳答案

这里有两种方法可以做到:

jsonRootValue["emptyArray"] = Json::Value(Json::arrayValue);
// or
jsonRootValue["emptyArray"] = Json::arrayValue;

关于c++ - 使用 jsoncpp 创建空的 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13293043/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com