gpt4 book ai didi

c++ - 使用 Boost 的 JSON 数据

转载 作者:行者123 更新时间:2023-11-28 05:00:50 25 4
gpt4 key购买 nike

是否可以使用boost读取下面的数据?

{
"ok": true,
"result": [
{
"update_id": 1235285,
"message": {
"message_id": 2,
"from": {
"id": 3325446,
"is_bot": false,
"first_name": "Test",
"language_code": "en-PH"
},
"chat": {
"id": 12532541,
"first_name": "Test Account",
"type": "private"
},
"date": 152014521,
"text": "Test Message"
}
}
]
}

最佳答案

您可以看到 linked post在评论中,

总而言之,您可以像下面那样从文件中读取 mfile.json :

    boost::property_tree::ptree pt;
boost::property_tree::read_json("myfile.json", pt);

print_contents( pt );

print_contents 是:

void print_contents( const boost::property_tree::ptree& pt)
{
using boost::property_tree::ptree;

for (const auto& x: pt )
{
std::cout << x.first << ": " << x.second.get_value<std::string>() << std::endl;
print_contents(x.second);
}
}

See Here


我本可以将其作为重复项关闭,但看起来没有“更好”的帖子来读取 json 文件

关于c++ - 使用 Boost 的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46054836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com