繁体   English   中英

C ++ JsonCpp从arrayValue更改objectValue

[英]C++ JsonCpp Change objectValue from an arrayValue

我想从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];

slot [selectIndex] =“ 1111”;

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

currentIndex需要取消unsigned 这是该API的一个不幸之处,请参见此处 (请参阅operator[](int) 。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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