C ++ JsonCpp从arrayValue更改objectValue

时间:2013-03-06 02:15:12

标签: c++ json jsoncpp

我想更改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);

2 个答案:

答案 0 :(得分:0)

的Json ::值及安培; slotList = root [" slotList"];

的Json ::值及安培; slot = slotList [currentIndex];

slot [selectIndex] =" 1111&#34 ;;

std :: cout<< root.toStyledString()<<的std :: ENDL;

答案 1 :(得分:0)

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