مثال خواندن پراپرتیهای json به صورت پویا و بدون داشتن کلید با nlohmann::json
کد
#json #dynamic #read #parse #nlohmann
کد
#include <iomanip>خروجی
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// a JSON text
char text[] = R"(
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated" : false,
"IDs": [116, 943, 234, 38793]
}
}
)";
// parse and serialize JSON
json j_complete = json::parse(text);
std::cout << std::setw(4) << j_complete << std::endl;
std::cout << "________________________" << std::endl;
for (const auto &prop : j_complete["Image"].items())
{
std::cout << "key: " << prop.key() << std::endl;
std::cout << "value: " << prop.value() << std::endl;
std::cout << "" << std::endl;
}
return 0;
}
{لینک کانال تلگرام : https://t.me/moderncpp_ir
"Image": {
"Animated": false,
"Height": 600,
"IDs": [
116,
943,
234,
38793
],
"Thumbnail": {
"Height": 125,
"Url": "http://www.example.com/image/481989943",
"Width": 100
},
"Title": "View from 15th Floor",
"Width": 800
}
}
________________________
key: Animated
value: false
key: Height
value: 600
key: IDs
value: [116,943,234,38793]
key: Thumbnail
value: {"Height":125,"Url":"http://www.example.com/image/481989943","Width":100}
key: Title
value: "View from 15th Floor"
key: Width
value: 800
#json #dynamic #read #parse #nlohmann
Telegram
ModernCpp.ir
site : moderncpp.ir
Mail : info@moderncpp.ir
Admin: @FONQRI
C++ tutorials and ...
Mail : info@moderncpp.ir
Admin: @FONQRI
C++ tutorials and ...