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

网站推广由什么样的人来做深圳全网推广

网站推广由什么样的人来做,深圳全网推广,北京装修公司全包价格,腾讯云可以用wordpress教程C 使用 nlohmann::json存储json文件 nlohmann::json 概述JSON 存储的示例以追加的方式存储json文件 nlohmann::json 概述 nlohmann::json 是 C 中一个流行的 JSON 库,由 Niels Lohmann 开发。它提供了一个简单而强大的 API,用于解析、构建、操作和序列化…

C++ 使用 nlohmann::json存储json文件

  • nlohmann::json 概述
  • JSON 存储的示例
  • 以追加的方式存储json文件

nlohmann::json 概述

nlohmann::json 是 C++ 中一个流行的 JSON 库,由 Niels Lohmann 开发。它提供了一个简单而强大的 API,用于解析、构建、操作和序列化 JSON 数据。

nlohmann::json 是一个模板类,可以用来表示 JSON 数据。它可以表示 JSON 对象、数组、数值、字符串、布尔值和空值等各种类型。nlohmann::json 支持方便的成员函数和操作符重载,使得对 JSON 数据的访问和修改非常直观和简便。

JSON 存储的示例

#include <iostream>
#include <fstream>
#include "nlohmann/json.hpp"using json = nlohmann::json;int main() {// 创建一个复杂的嵌套 JSON 对象json data = {{"name", "John"},{"age", 30},{"is_student", false},{"grades", {85, 92, 78, 90}},{"address", {{"street", "123 Main St"},{"city", "New York"},{"country", "USA"}}},{"friends", {{{"name", "Alice"}, {"age", 28}},{{"name", "Bob"}, {"age", 32}},{{"name", "Claire"}, {"age", 27}}}}};// 将 JSON 对象写入文件std::ofstream file("data.json");if (file.is_open()) {file << std::setw(4) << data << std::endl;file.close();std::cout << "JSON data has been written to file." << std::endl;} else {std::cerr << "Failed to open file for writing." << std::endl;}return 0;
}

以追加的方式存储json文件

在打开文件时使用 std::ofstream 的 std::ios_base::app 模式来追加写入数据。

std::ofstream json_out_file_("data.json", std::ios_base::app);

以下是 nlohmann::json 常见的用法和功能:

  1. 解析和构建 JSON 数据:

    nlohmann::json json_data = nlohmann::json::parse(json_string);  // 解析 JSON 字符串为 JSON 对象
    nlohmann::json json_data = {{ "key", "value" }, { "array", {1, 2, 3} }};  // 构建 JSON 对象// 在 JSON 对象中添加新的字段或修改现有字段
    json_data["new_key"] = "new_value";
    json_data["existing_key"] = 123;// 创建 JSON 数组
    nlohmann::json json_array = {1, 2, 3, 4, 5};
    
  2. 访问和操作 JSON 数据:

    std::string value = json_data["key"];  // 获取 JSON 对象中指定字段的值
    int size = json_array.size();  // 获取 JSON 数组的长度
    bool is_object = json_data.is_object();  // 检查 JSON 数据是否为对象// 遍历 JSON 对象或数组的元素
    for (const auto& element : json_data) {std::string key = element.first;nlohmann::json value = element.second;// 处理元素
    }// 修改 JSON 数组的元素
    json_array[2] = 10;
    
  3. 序列化和反序列化 JSON 数据:

    std::string serialized_json = json_data.dump();  // 将 JSON 对象序列化为字符串// 从文件中读取 JSON 数据并解析
    std::ifstream input_file("data.json");
    nlohmann::json json_data;
    input_file >> json_data;
    

nlohmann::json 提供了一种便捷和高效的方式来处理 JSON 数据,使得在 C++ 程序中解析、生成和操作 JSON 变得更加简单。它非常适合于处理各种 JSON 数据,包括配置文件、API 响应和数据交换等。

http://www.dt0577.cn/news/37057.html

相关文章:

  • wordpress 导入网站模板白云区新闻
  • 自己开个网站常德今日头条新闻
  • 做b2b网站赚钱深圳优化公司
  • 没有网站备案可以做诚信认证嘛免费广州seo
  • 一般网站版式有哪几种在线超级外链工具
  • 建设银行车主卡网上交罚款网站女教师遭网课入侵视频大全
  • 邢台做网站安卓优化大师最新版下载
  • 济南做网站的价格青岛网络seo公司
  • 服饰 公司 网站建设百度网盘网页
  • 电子商务网站建设实验原理吸引客流的25个技巧
  • 外贸做网站推广手机百度网址大全首页
  • 关键词优化排名易下拉效率网站关键词优化报价
  • 橙子建站仅向商家提供技术如何做一个网站
  • 桂林做网站推广恶意点击软件怎样使用
  • 做兼职翻译的网站新闻平台发布
  • 门户型网站建设方案查关键词的排名工具
  • 未来 网站开发 知乎重庆seo优化
  • 安徽地方政府网站建设情况搜索引擎的营销方法有哪些
  • 一键生成文案的网站保定seo推广公司
  • 学做花蛤的网站加盟教育培训哪个好
  • 网站建设技术服务2345网址导航官网官方电脑版下载
  • 律师做几个网站企业营销策划有限公司
  • WordPress站群更新流程优化
  • 陕西省城乡建设学校网站上海营销seo
  • 网站的空间什么意思线上推广渠道主要有哪些
  • 做视频网站赚做视频网站赚厦门seo网络优化公司
  • 网站做地区定位跳转权重查询爱站网
  • 开通网站的会计科目怎么做湖南知名网络推广公司
  • 关于做香奈儿网站的PPT今天的最新消息新闻
  • 网站301在哪里做广州网站制作实力乐云seo