当前位置:网站首页>nlohmann json 使用指南【visual studio 2022】
nlohmann json 使用指南【visual studio 2022】
2022-07-30 18:35:00 【一只公羊】
一、JSON for Modern C++
官网:https://github.com/nlohmann/json
下载:https://github.com/nlohmann/json/releases

二、集成到 visual studio 2022
2.1 解压include.zip,拷贝include下的include到工程文件夹下:
2.2. 修改工程属性里的:附加包含目录
2.3 测试
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
json j; //首先创建一个空的json对象
j["pi"] = 3.141; //然后通过名称/值对的方式进行初始化,此时名称"pi"对应的数值就是3.141
j["happy"] = true; //将名称"happy"赋值为true
j["name"] = "Niels"; //将字符串"Niels"存储到"name"
j["nothing"] = nullptr; //"nothing"对应的是空指针
j["answer"]["everything"] = 42; //对对象中的对象进行初始化
j["list"] = {
1, 0, 2}; //使用列表初始化的方法对"list"数组初始化
j["object"] = {
{
"currency", "USD"}, {
"value", 42.99}}; //对对象进行初始化
std::string s = j.dump(); // {"happy":true,"pi":3.141}
std::cout << j.dump(4) << std::endl;
return 0;
}
边栏推荐
猜你喜欢

LeetCode Exercise - Two Questions About Finding Sum of Array Elements

好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%

CCNA-子网划分(VLSM)

【AGC】构建服务1-云函数示例

Codeblocks + Widgets create window code analysis

natural language processing nltk

After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...

【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list

CIMC Shilian Dafeitong is the global industrial artificial intelligence AI leader, the world's top AI core technology, high generalization, high robustness, sparse sample continuous learning, industri

C# wpf 无边框窗口添加阴影效果
随机推荐
AWS console
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
【HMS core】【FAQ】HMS Toolkit典型问题合集1
智慧中控屏
ROS 环境使用第三方动态链接库(.so)文件
网络基础(三)01-网络的基础概念——URL地址组成之协议、主机地址、路径和参数&127.0.0.1本地回环地址& 查看网址IP地址并访问之ping空格+网址&netstat -anb查看本机占用端口
OSPF详解(4)
Pytorch foundation -- tensorboard use (1)
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
The sixteenth issue of eight-part article Balabala said (MQ)
Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
The use of @ symbol in MySql
Web结题报告
自然语言处理nltk
【HMS core】【ML Kit】机器学习服务常见问题FAQ(二)
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
高精度加法
【HarmonyOS】【FAQ】鸿蒙问题合集3
[OC study notes] attribute keyword
kotlin by lazy