当前位置: 首页 > news >正文

nlohmann json:检查类型并取出数据

经常需要获取json中的某个key是否存在,如果存在的话取出其中的数据,可以参照下例:

#include <iostream>
#include <nlohmann/json.hpp>
using namespace std;
using json = nlohmann::json;template <typename T>
struct is_std_vector : std::false_type {};template <typename T, typename Alloc>
struct is_std_vector<std::vector<T, Alloc>> : std::true_type {};template <typename T>
bool checkJsonType(const nlohmann::json& j)
{if constexpr (std::is_same_v<T, int>)return j.is_number_integer();else if constexpr (std::is_same_v<T, double>)return j.is_number();else if constexpr (std::is_same_v<T, std::string>)return j.is_string();else if constexpr (std::is_same_v<T, 
http://www.dtcms.com/a/205522.html

相关文章:

  • 深入解析C++静态成员变量与函数
  • 网络安全之身份验证绕过漏洞
  • 前沿技术:如何从多模态文件中自动提取有效信息?
  • 学习路之uniapp--unipush2.0推送功能--给自己发通知
  • PostGIS实现栅格数据导出PNG应用实践【ST_AsPNG 】
  • 【Redis8】最新安装版与手动运行版
  • springboot3+vue3融合项目实战-大事件文章管理系统-更新文章分类和增加文章分类优化-分组校验
  • FlashAttention:传统自注意力( Self-Attention)优化加速实现
  • BEVDet
  • 实战5:个性化数字艺术生成与销售
  • 【泛微系统】后端开发Action常用方法
  • 项目交付标准不明确,如何确保验收顺利
  • 谷歌I/O 2025 完全指南:由Gemini开创的AI新时代及其对我们未来的影响
  • Bently Nevada 3500/61 非隔离I/O模块 (133819-02)
  • c++11特性——可变参数模板及emplace系列接口
  • 电子电路:怎么理解放大电路中集电极电流Ic漂移?
  • 命令行删除node_modules
  • 系统工程与一般系统理论 | 技术 / 应用 / 跨领域认知融合
  • 时源芯微|六大步骤解决EMC问题
  • 【AI流程应用】智能知识库搭建与实战应用
  • 【Linux】借助gcc源码修改,搜索头文件当前进展
  • 6-码蹄集600题基础python篇
  • 为什么可以不重写m1方法
  • 英伟达显卡驱动怎么安装 使用驱动人生轻松安装
  • 嵌入式自学第二十五天(5.21)
  • 10-码蹄集600题基础python篇
  • 【Python生成器全解析】从基础到高阶应用实战
  • Jenkins (七) - Docker Harbor
  • 三维表面轮廓仪的维护保养是确保其长期稳定运行的关键
  • Java操作数据库,JDBC