2013-03-06 2 views
1

Я хочу изменить значение от slotList.C++ JsonCpp Измените объектValue from arrayValue

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); 
+0

Где находится 'currentIndex' и' selectIndex'? –

+0

currentIndex равен 1 и selectIndex равен 1 одинаково :) – realmasse

ответ

0

Json :: Значение & slotList = корень [ "slotList"];

Json :: Значение & slot = slotList [currentIndex];

гнездо [selectIndex] = "1111";

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

0

currentIndex должно быть unsigned. Это неудачная причуда API, задокументированная here. (См. operator[](int).)