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

wordpress4.9.8下载旺道seo软件

wordpress4.9.8下载,旺道seo软件,个人网站一键生成,阜阳手机网站制作目录 准备环境VS 环境下配置编译使用 基础概述Json 数组Json 对象 Jsoncpp 的使用ValueFastWriterReader示例 如果想要 Json 部署在 Linux 上 参考: https://blog.csdn.net/2303_76953932/article/details/142703683?spm1001.2014.3001.5502 C中原生不支持 Json,所…

目录

  • 准备环境
    • VS 环境下配置
      • 编译
      • 使用
  • 基础
    • 概述
    • Json 数组
    • Json 对象
  • Jsoncpp 的使用
    • Value
    • FastWriter
    • Reader
    • 示例

如果想要 Json 部署在 Linux 上
参考: https://blog.csdn.net/2303_76953932/article/details/142703683?spm=1001.2014.3001.5502

C++中原生不支持 Json,所以需要导入 Jsoncpp

准备环境

  1. 下载 Jsoncpp

从 github 上下载源码

# 这是链接地址
https://github.com/open-source-parsers/jsoncpp

这里我使用的是 git 工具克隆了一份数据下来

git clone git@github.com:open-source-parsers/jsoncpp.git

没有 git 工具就点击 code ,然后点击 Download ZIP 下载 ZIP 文件,然后解压到你想要保存的目录下即可

  1. 下载 Cmake 工具
  • 这个工具是为了编译这个 Jsoncpp 源码编译成动态库,然后需要使用的时候直接使用这个库即可
  • 否则需要把这些源码文件和项目文件放一起编译,这样不利于维护,且显得体量过大

VS 环境下配置

  • 由于需要在 VS 上写代码,所以需要将源码编译成 VS 环境下的动态库文件
  • 因此这里演示如何配置

编译

  1. 打开 cmake 工具,然后选择对于的文件路径,第一个路径为下载 Jsoncpp 源码后的路径,第二个路径为编译后文件的路径

QQ_1726993980695

  1. 选择好路径后,点击左下角的 configure 按钮,然后弹出对话框,然后选择对于的 VS 版本,也就是自己本地的版本,我的是 VS2022,就选择了这个,其他选项默认即可

QQ_1726994148628

  1. 点击 Finish 后,等待几秒,点击 Generate 生成 VS 项目,生成后,去对应的路径点击 jsoncpp.sln 打开这个项目

  2. 找到 jsoncpp_lib ,右击选择生成,此时就能得到我们想要的库文件了

使用

  1. 由于需要在编写代码时候需要 jsoncpp 对应的头文件,因此配置头文件,有两种方式
  • 将头文件放到项目目录下,直接被项目包含引用
  • 将头文件放到一个本地固定目录,以后就不再动了,在 VS 项目属性中设置包含这个目录

这里选择第二种

将源码 jsoncpp 中的 include 目录拷贝到本地,注意是源码中的 include 目录,不是生成的 VS 项目中的 include 目录

QQ_1726994990715

由于这个 include 目录下有个 json 目录,并且这个目录中才是存放的头文件,所以访问里面的头文件时需要这样

#include <json/json.h>

不建议把头文件移出,这会破坏整个目录结构,存在隐患

  1. 还要将对应的动态库也放在本地固定目录
  • 一个是前面步骤中生成的 vs 项目的 bin 目录下的 Debug 目录中的 jsoncpp.dllQQ_1726995171031

  • 一个是前面步骤中生成的 vs 项目的 lib 目录下的 Debug 目录中的 jsoncpp.libQQ_1726995275746

将这两个文件复制到之前 include 同级目录下,新建一个 lib 目录,放在这里面 QQ_1726995352345

  1. 接下来就是在 VS 中配置了

点击小扳手,打开项目属性 QQ_1726995504028

指定头文件的路径:点击这个,然后编辑包含目录

QQ_1726995576711 1

填写刚刚拷贝 include 的固定目录路径位置

QQ_1726995678575

指定库路径:再编辑库目录

QQ_1726995765142

将刚刚拷贝动态库和导入库到的固定目录路径填写进去

QQ_1726995799658

还需要告诉 VS 需要加载的动态库是哪一个

QQ_1726995872192

填写导入库的名称,也就是 jsoncpp.lib

QQ_1726995914039

到这里就配置完成了,如果执行报错不能找到动态库 jsoncpp.dll 只需要将这个文件拷贝到当前 VS 测试项目代码位置即可

QQ_1726996527484

测试代码:

#include <iostream>
#include <json/json.h>  
using namespace Json;
using namespace std;
int main()
{Value root;root["message"] = "Hello, JsonCpp!";cout << root.toStyledString() << std::endl;return 0;
}

基础

概述

  • 是一个完全独立于编程语言的文本格式,用来存储和表示数据的
  • Json 是一种数据格式,和语言无关,在什么语言中都可以使用 Json

用途:

  • 组织数据(数据序列化),用于数据的网络传输
  • 组织数据(数据序列化),写磁盘文件实现数据的持久化存储(一般以. json 作为文件后缀)

Json 中主要有两种数据格式:Json 数组和 Json 对象,并且这两种格式可以交叉嵌套使用

Json 数组

  • Json 数组使用 [] 表示,[] 里边是元素,元素和元素之间使用逗号间隔,最后一个元素后边没有逗号
  • 一个 Json 数组中支持同时存在多种不同类型的成员,包括:整形、 浮点、 字符串、 布尔类型、 json 数组、 json 对象、 空值-null
["zhangsan", 176, 20, false,["北京", "上海", "天津", "重庆"],{"Sex": "boy", "father: "Alice"} 
]

Json 对象

  • Json 对象使用 {} 来描述,每个 Json 对象中可以存储若干个元素,每一个元素对应一个键值对(key:value 结构),元素和元素之间使用逗号间隔,最后一个元素后边没有逗号
  • 键值(key)必须是字符串,位于同一层级的键值不要重复(因为是通过键值取出对应的 value 值)
  • value 值的类型是可选的,可根据实际需求指定,可用类型包括:整形、 浮点、 字符串、 布尔类型、 json 数组、 json 对象、 空值-null

Jsoncpp 的使用

jsoncpp 库中的类被定义到了一个 Json 命名空间中

using namespace Json;

使用 jsoncpp 库解析 json 格式的数据,我们只需要掌握三个类:

  • Value 类:将 json 支持的数据类型进行了包装,最终得到一个 Value 类型
  • FastWriter 类:将 Value 对象中的数据序列化为字符串
  • Reader 类:反序列化,将 json 字符串解析成 Value 类型

Value

// 判断保存的类型是否是 string / 数组 / 对象
// 这里这列举了三个,还有其他数据类型,如 int, double....
bool isString() const;
bool isArray() const;
bool isObject() const;
// 将 Value 对象转换为实际类型
Int asInt() const;
JSONCPP_STRING asString() const;
const char* asCString() const
// 对 Json 数组的操作
ArrayIndex size() const;
Value& operator[](ArrayIndex index);
Value& operator[](int index);        // 可以直接下标访问
const Value& operator[](ArrayIndex index) const;
const Value& operator[](int index) const;// 根据下标的 index 返回这个位置的 value 值
// 如果没找到这个 index 对应的 value, 返回第二个参数d efaultValue
Value get(ArrayIndex index, const Value& defaultValue) const;
Value& append(const Value& value);
const_iterator begin() const;
const_iterator end() const;
iterator begin();
iterator end();
// 对 json 对象的操作
Value& operator[](const char* key);
Value& operator[](const JSONCPP_STRING& key);
Value& operator[](const StaticString& key);const Value& operator[](const char* key) const;
const Value& operator[](const JSONCPP_STRING& key) const;// 通过key, 得到value值
Value get(const char* key, const Value& defaultValue) const;
Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
Value get(const CppTL::ConstString& key, const Value& defaultValue) const;// 得到对象中所有的键值
typedef std::vector<std::string> Members;
Members getMemberNames() const;

FastWriter

// 将 Value 对象数据序列化为 string
// 序列化得到的字符串有样式 -> 带换行 -> 方便阅读 -> 适用于写配置文件的时候
std::string toStyledString() const;// 将数据序列化 -> 单行 -> 适用于网络传输的时候
std::string Json::FastWriter::write(const Value& root);

Reader

// Reader 类
bool Json::Reader::parse(const std::string& document,Value& root, bool collectComments = true);参数:- document: json格式字符串- root: 传出参数, 存储了json字符串中解析出的数据- collectComments: 是否保存json字符串中的注释信息// 通过begindoc和enddoc指针定位一个json字符串
// 这个字符串可以是完成的json字符串, 也可以是部分json字符串
bool Json::Reader::parse(const char* beginDoc, const char* endDoc,Value& root, bool collectComments = true);// write的文件流  -> ofstream
// read的文件流   -> ifstream
// 假设要解析的json数据在磁盘文件中
// is流对象指向一个磁盘文件, 读操作
bool Json::Reader::parse(std::istream& is, Value& root, bool collectComments = true);

示例

准备的 Json 数据

[12, 12.34, true, "tom", ["jack", "ace", "robin"], {"sex":"man", "girlfriend":"lucy"}
]

写 Json

void writeJson()
{// 将最外层的数组看做一个 Value// 最外层的 Value 对象创建Value root;// Value 有一个参数为 int 行的构造函数root.append(12);	// 参数进行隐式类型转换root.append(12.34);root.append(true);root.append("tom");// 创建并初始化一个子数组Value subArray;subArray.append("jack");subArray.append("ace");subArray.append("robin");root.append(subArray);// 创建并初始化子对象Value subObj;subObj["sex"] = "woman";  // 添加键值对subObj["girlfriend"] = "lucy";root.append(subObj);// 序列化// 有格式的字符串string str = root.toStyledString();// 一整行// FastWriter f;// string str = f.write(root);// 将序列化的字符串写磁盘文件ofstream ofs("test.json");ofs << str;ofs.close();
}

读 Json

void readJson()
{// 1. 将磁盘文件中的 json 字符串读到磁盘文件ifstream ifs("test.json");// 2. 反序列化 -> value 对象Value root;Reader r;r.parse(ifs, root);// 3. 从 value 对象中将数据依次读出if (root.isArray()){// 数组, 遍历数组for (int i = 0; i < root.size(); ++i){// 依次取出各个元素, 类型是 value 类型Value item = root[i];// 判断 item 中存储的数据的类型if (item.isString()){cout << item.asString() << ", ";}else if (item.isInt()){cout << item.asInt() << ", ";}else if (item.isBool()){cout << item.asBool() << ", ";}else if (item.isDouble()){cout << item.asFloat() << ", ";}else if (item.isArray()){   // 数组for (int j = 0; j < item.size(); ++j) {cout << item[j].asString() << ", ";}}else if (item.isObject()){// 对象// 得到所有的keyValue::Members keys = item.getMemberNames();for (int k = 0; k < keys.size(); ++k) {cout << keys.at(k) << ":" << item[keys[k]] << ", ";}}}cout << endl;}
}

上述读数据如此之繁琐,是因为假设我们完全不知道 Json 数据封装的数据格式 但是实际中,我们其实大多是知道这个数据格式的,也就能直接读取对应数据了


说明:参考学习:https://subingwen.cn/


文章转载自:
http://grinding.tsnq.cn
http://labyrinthic.tsnq.cn
http://encrust.tsnq.cn
http://imperiality.tsnq.cn
http://submultiple.tsnq.cn
http://sinuation.tsnq.cn
http://sequin.tsnq.cn
http://sicative.tsnq.cn
http://enclave.tsnq.cn
http://transcript.tsnq.cn
http://bywalk.tsnq.cn
http://heliogram.tsnq.cn
http://vaporescence.tsnq.cn
http://sublanguage.tsnq.cn
http://bicorn.tsnq.cn
http://hypnus.tsnq.cn
http://postvocalic.tsnq.cn
http://rca.tsnq.cn
http://rascallion.tsnq.cn
http://quadruplication.tsnq.cn
http://dilettantism.tsnq.cn
http://during.tsnq.cn
http://regina.tsnq.cn
http://interabang.tsnq.cn
http://overcloud.tsnq.cn
http://eglantine.tsnq.cn
http://stodgy.tsnq.cn
http://ultraphysical.tsnq.cn
http://lapidescent.tsnq.cn
http://decagynous.tsnq.cn
http://testing.tsnq.cn
http://smartless.tsnq.cn
http://fisherboat.tsnq.cn
http://accusation.tsnq.cn
http://faln.tsnq.cn
http://lensman.tsnq.cn
http://inimical.tsnq.cn
http://scopophilia.tsnq.cn
http://canonise.tsnq.cn
http://lorn.tsnq.cn
http://phrenologist.tsnq.cn
http://bagnio.tsnq.cn
http://superficiality.tsnq.cn
http://tournament.tsnq.cn
http://beaker.tsnq.cn
http://sessioneer.tsnq.cn
http://correspond.tsnq.cn
http://canaan.tsnq.cn
http://venal.tsnq.cn
http://mu.tsnq.cn
http://venusberg.tsnq.cn
http://streuth.tsnq.cn
http://flyboat.tsnq.cn
http://eirenic.tsnq.cn
http://ringleader.tsnq.cn
http://subhead.tsnq.cn
http://putt.tsnq.cn
http://laplacian.tsnq.cn
http://petrous.tsnq.cn
http://sultaness.tsnq.cn
http://circlorama.tsnq.cn
http://protease.tsnq.cn
http://pygmy.tsnq.cn
http://plastosome.tsnq.cn
http://ruapehu.tsnq.cn
http://hamartoma.tsnq.cn
http://truffled.tsnq.cn
http://amontillado.tsnq.cn
http://starboard.tsnq.cn
http://trigo.tsnq.cn
http://hydrokinetics.tsnq.cn
http://hardball.tsnq.cn
http://ticklish.tsnq.cn
http://scaredy.tsnq.cn
http://architectonic.tsnq.cn
http://submersible.tsnq.cn
http://prepreerence.tsnq.cn
http://ligure.tsnq.cn
http://visuosensory.tsnq.cn
http://hexasyllabic.tsnq.cn
http://reddle.tsnq.cn
http://continuously.tsnq.cn
http://contradance.tsnq.cn
http://besotted.tsnq.cn
http://covalence.tsnq.cn
http://gamophyllous.tsnq.cn
http://pesaro.tsnq.cn
http://cryptosystem.tsnq.cn
http://irreversibility.tsnq.cn
http://pleasantry.tsnq.cn
http://desultoriness.tsnq.cn
http://streak.tsnq.cn
http://humoral.tsnq.cn
http://tergiversate.tsnq.cn
http://fluky.tsnq.cn
http://amidah.tsnq.cn
http://meself.tsnq.cn
http://quinquevalent.tsnq.cn
http://roti.tsnq.cn
http://fanega.tsnq.cn
http://www.dt0577.cn/news/107990.html

相关文章:

  • nodejs 做网站js交件网站快速被百度收录
  • 露天做愛偷拍网站口碑营销的特点
  • 源代码网站培训网站搜索优化找哪家
  • 公司网站怎么做微信怎么推广自己的产品
  • 网站源码对应的数据库怎么做网页查询
  • 哪个网站教做ppt外包公司是正规公司吗
  • 做购物网站的公司百度收录查询
  • 东莞百度搜索网站排名湛江百度网站快速排名
  • 合肥龙岗医院网站建设2024年重大新闻简短
  • 陕西省建设资质是哪个网站北京seo外包
  • 牟平网站建设学营销app哪个更好
  • 长春专业网站建设价格自己怎样在百度上做推广
  • 南宁微信网站制作seo谷歌外贸推广
  • 网站开发工资一般多少钱什么软件可以发帖子做推广
  • 个人网站设计需求分析免费建站网站大全
  • 巫山那家做网站重庆seo教程博客
  • 网站备案连接爱站网关键词查询工具
  • 宁波市北仑区建设局网站营销型网站建设解决方案
  • wordpress手机网站怎么做推广竞价账户托管
  • 青岛市区商场黄页谷歌seo优化推广
  • 免费视频app软件推广优化排名
  • 做网站好一点的公司seo免费诊断电话
  • 华升建设集团有限公司网站产品网络推广方案
  • 电商网站详细设计seo自学网官网
  • 重庆百度网站快速排名电脑版百度入口
  • b2b门户网站建设方案六六seo基础运营第三讲
  • 女人和男人做爰网站长沙网站seo排名
  • 如何做电影网站挣钱有名的seo外包公司
  • 做暖暖小视频网站谷歌seo网站推广怎么做优化
  • 做内部优惠券网站百度近日收录查询