当前位置:网站首页>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;
}
边栏推荐
- 【Qt Designer工具的使用】
- 【AGC】构建服务1-云函数示例
- Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布
- Common linked list problems and their Go implementation
- 终端分屏工具Terminalx的使用
- "Ruffian Heng Embedded Bimonthly" Issue 59
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
- 基础架构之Mongo
- OSPF详解(3)
- Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
猜你喜欢
kotlin的by lazy
CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL
WeChat Mini Program Cloud Development | Urban Information Management
Recommendation | People who are kind to you, don't repay them by inviting them to eat
6块钱1斤,日本公司为何来中国收烟头?
银行适用:此文能够突破你的运维流程管理问题
Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
网络基础(三)01-网络的基础概念——URL地址组成之协议、主机地址、路径和参数&127.0.0.1本地回环地址& 查看网址IP地址并访问之ping空格+网址&netstat -anb查看本机占用端口
随机推荐
银行适用:此文能够突破你的运维流程管理问题
Hello, my new name is "Bronze Lock/Tongsuo"
自然语言处理nltk
第4章 控制执行流程
沉浸式体验科大讯飞2022消博会“官方指定产品”
MySQL data types
【总结】1396- 60+个 VSCode 插件,打造好用的编辑器
AWS 控制台
arcpy获取要素类(属性表)包含的数目
运营 23 年,昔日“国内第一大电商网站”黄了...
DevEco Studio3.0下载失败,提示An unknown error occurred
ByteArrayInputStream class source code analysis
[Use of Qt Designer tool]
【Prometheus】Prometheus联邦的一次优化记录[续]
积性函数
C# wpf 无边框窗口添加阴影效果
SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
图解LeetCode——11. 盛最多水的容器(难度:中等)
LeetCode Exercise - Two Questions About Finding Sum of Array Elements
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?