我有nlohmann json对象:
<%= link_to image_tag ('functional-med.png', class:"nutricion"), 'https://www.ifm.org/' %>
我可以毫无问题地获取数组中的值:str = uuid [“ uuid”] [0];
但是我如何才能自己获得数组名称?
答案 0 :(得分:0)
您可以从json对象获取基础映射,该对象为您提供了数组名称和数组。如果您只想遍历所有简单的项目。
#include <iostream>
#include <json.hpp>
using json = nlohmann::json;
int main()
{
json uuid = R"(
{
"uuid": ["aaa","bbb","ccc"],
"uuie": ["aaa","bbb","ccc"],
"uuif": ["aaa","bbb","ccc"]
}
)"_json;
if (uuid.is_object())
{
auto obj = uuid.get<json::object_t>();
for (auto& kvp : obj)
{
std::cout << kvp.first << ":" << kvp.second << "\n";
}
}
for (auto& item : uuid)
{
std::cout << item << "\n";
}
return 0;
}