我想在c++中使用api,当我搜索时,我发现nlohmann/json库,它看起来真的很流行,但没有人谈论如何获取fetch函数提供的数组。如何以cpp文件中的变量形式从api获取信息?
发布于 2021-01-29 10:25:46
不太理解你的描述,我想你的意思是你想要得到JSON数组?您可以尝试这样做:
std::string ss= R"(
{
"test-data":
[
{
"name": "tom",
"age": 11
},
{
"name": "jane",
"age": 12
}
]
}
)";
json myjson = json::parse(ss);
auto &students = myjson["test-data"];
for(auto &student : students) {
cout << "name=" << student["name"].get<std::string>() << endl;
}https://stackoverflow.com/questions/65947472
复制相似问题