C++ JsonCpp Change objectValue from an arrayValue

C++ JsonCpp Change objectValue from an arrayValue

本文关键字:an arrayValue from objectValue JsonCpp Change C++      更新时间:2023-10-16

我想更改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::值&slotList=root["slotList"];

Json::价值&slot=slotList[currentIndex];

slot[selectIndex]="1111";

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

currentIndex需要是unsigned。这是API的一个不幸的怪癖,这里记录了这一点。(参见operator[](int)。(