简体   繁体   中英

C++ JsonCpp Change objectValue from an arrayValue

I want to change the value from slotList .

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

How can I solve this problem?

Here's what I tried:

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" ]
   ]
}

Code:

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];

slot[selectIndex] = "1111";

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

currentIndex needs to be unsigned . That is an unfortunate quirk of the API, documented here . (See operator[](int) .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM