# C++Json序列化到文件 **Repository Path**: deng-yongsheng/cpp-json-demo ## Basic Information - **Project Name**: C++Json序列化到文件 - **Description**: C++对象Json序列化保存到文件demo - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-12 - **Last Updated**: 2022-10-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # C++对象Json序列化保存到文件demo 使用[nlohmann/json](https://github.com/nlohmann/json),文档地址:[https://json.nlohmann.me/](https://json.nlohmann.me/) # 项目结构 ## entities.h + Point类 ```text 描述一个点的位置,包含横坐标和纵坐标 ``` + Rectangle类 ```text 描述一个矩形,包含左上点坐标和右下点坐标 ``` + Recognition类 ```text 识别结果,包含一个矩形、识别类别、置信度 ``` + Record类 ```text 一个识别结果集记录,包含多个Recognition对象 ``` ## JsonSaver.h + JsonSaver类 ```text 在构造函数中打开文件用于输出结果 在析构函数中自动关闭输出流 ``` + Write静态方法 ```text 直接保存到文件,无需实例化JsonSaver类 ``` # 使用示例 ```c++ #include "JsonSaver.h" int main() { // 实例化一个识别结果记录 Record r({ Recognition( Rectangle(1,1,2,2), // 矩形的位置和大小 "face1", // 识别的分类情况 0.88), // 置信度 Recognition( Rectangle(1,1,2,2), "face2", 0.99) }); JsonSaver::Write(r); // 调用JsonSaver的静态成员保存识别结果 } ```