gpt4 book ai didi

C++ JsonCpp 从 arrayValue 更改 objectValue

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:40 25 4
gpt4 key购买 nike

我想更改 slotList 的值。

slotList[1][1] = "1234";

我该如何解决这个问题?

这是我尝试过的:

JSON:

{

"slotList" : [

[ "1452", "1452", "1452", "1452", "1452" ],
[ "1452", "1452", "1452", "1452", "1452" ],
[ "1452", "1452", "1452", "1452", "1452" ],
[ "1452", "1452", "1452", "1452", "1452" ],
[ "1452", "1452", "1452", "1452", "1452" ]
]
}

代码:

if (bIsParsed == true)
{
Json::Value slotList = root["slotList"];

Json::Value slot = slotList[currentIndex];
Json::Value value = "111"; // what is wrong? do not change anything! OMG!
slot[selectIndex].swap(value);
}

Json::StyledWriter writer;
string jsonData = writer.write(root);

最佳答案

Json::Value& slotList = root["slotList"];

Json::Value& slot = slotList[currentIndex];

插槽[selectIndex] = "1111";

std::cout << root.toStyledString() << std::endl;

关于C++ JsonCpp 从 arrayValue 更改 objectValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15237785/

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