我是 C++ 的新手并试图使用 nlohmann 库,但我很困惑。我想从 json 修改对象数组。
json =
{
"a": "xxxx",
"b": [{
"c": "aaa",
"d": [{
"e": "yyy"
},
{
"e": "sss",
"f": "fff"
}
]
}]
}
Run Code Online (Sandbox Code Playgroud)
现在我想e用上述结构中的“example”替换值。有人可以帮助我。
我尝试遍历 json 结构并能够读取“e”值但无法替换它。我试过:`
std::vector<std::string> arr_value;
std::ifstream in("test.json");
json file = json::parse(in);
for (auto& td : file["b"])
for (auto& prop : td["d"])
arr_value.push_back(prop["e"]);
//std::cout<<"prop" <<prop["e"]<< std::endl;
for (const auto& x : arr_value)
std::cout <<"value in vector string= " <<x<< "\n";
for (decltype(arr_value.size()) i = 0; i <= arr_value.size() …Run Code Online (Sandbox Code Playgroud)