2

我想将值从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);
4

2 回答 2

0

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

于 2015-02-16T23:50:27.120 回答
0

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

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

插槽 [selectIndex] = "1111";

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

于 2013-03-07T01:20:29.197 回答