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

照片编辑器app重庆seo建站

照片编辑器app,重庆seo建站,网站防止挂马应该怎么做,贵阳网站制作贵阳网站建设哪家好目录 一,Jsoncpp库序列化和反序列化 二,bundle文件压缩库 2.1 文件压缩 2.2 文件解压 一,Jsoncpp库序列化和反序列化 首先我们需要先了解一下json是什么,json是一种数据交换格式,采用完全独立于编程语言的文本格式来…

目录

一,Jsoncpp库序列化和反序列化

二,bundle文件压缩库

 2.1 文件压缩

2.2 文件解压


一,Jsoncpp库序列化和反序列化

首先我们需要先了解一下json是什么,json是一种数据交换格式,采用完全独立于编程语言的文本格式来存储和表示数据。

char name = "小明";
int age = 18;
float score[3] = {88.5, 99, 58};
则json这种数据交换格式是将这多种数据对象组织成为一个字符串:
[{"姓名" : "小明","年龄" : 18,"成绩" : [88.5, 99, 58]},{"姓名" : "小黑","年龄" : 18,"成绩" : [88.5, 99, 58]}
]

json数据类型:对象,数组,字符串,数字

对象:使用花括号{}括起来的表示一个对象。

数组:使用中括号[]括起来的表示一个数组。

字符串:使用常规双引号""括起来的表示一个字符串

数字:包括整形和浮点型,直接使用。

 

而Jsoncpp库主要用于Json格式的序列化和反序列化,可以将多个数据对象组织成Json格式的字符串(序列化),也可以将Json格式的字符串解析获得多个数据对象(反序列化)

 这其中主要借助三个类以及其对应的少量成员函数完成:

//Json数据对象类
class Json::Value{Value &operator=(const Value &other); //Value重载了[]和=,因此所有的赋值和获取数据都可以通过Value& operator[](const std::string& key);//简单的方式完成 val["姓名"] = "小明";Value& operator[](const char* key);Value removeMember(const char* key);//移除元素const Value& operator[](ArrayIndex index) const; //val["成绩"][0]Value& append(const Value& value);//添加数组元素val["成绩"].append(88); ArrayIndex size() const;//获取数组元素个数 val["成绩"].size();std::string asString() const;//转string 	 string name = val["name"].asString();const char* asCString() const;//转char*   char *name = val["name"].asCString();Int asInt() const;//转int				int age = val["age"].asInt();float asFloat() const;//转floatbool asBool() const;//转 bool
};//json序列化类,低版本用这个更简单
class JSON_API Writer {virtual std::string write(const Value& root) = 0;
}
class JSON_API FastWriter : public Writer {virtual std::string write(const Value& root);
}
class JSON_API StyledWriter : public Writer {virtual std::string write(const Value& root);
}
//json序列化类,高版本推荐,如果用低版本的接口可能会有警告
class JSON_API StreamWriter {virtual int write(Value const& root, std::ostream* sout) = 0;
}
class JSON_API StreamWriterBuilder : public StreamWriter::Factory {virtual StreamWriter* newStreamWriter() const;
}//json反序列化类,低版本用起来更简单
class JSON_API Reader {bool parse(const std::string& document, Value& root, bool collectComments = true);
}
//json反序列化类,高版本更推荐
class JSON_API CharReader {virtual bool parse(char const* beginDoc, char const* endDoc, Value* root, std::string* errs) = 0;
}
class JSON_API CharReaderBuilder : public CharReader::Factory {virtual CharReader* newCharReader() const;
}

接下来我们来举例使用一下:

#include <iostream>
#include <sstream>
#include <memory>
#include <jsoncpp/json/json.h>int main()
{// 序列化const char *name1 = "张三";int age1 = 18;float grade1[3] = {77.1, 64.74, 56.11};Json::Value val;val["姓名"] = name1;val["年龄"] = age1;val["成绩"].append(grade1[0]);val["成绩"].append(grade1[1]);val["成绩"].append(grade1[2]);Json::StreamWriterBuilder swb;std::shared_ptr<Json::StreamWriter> writer_ptr(swb.newStreamWriter());std::ostringstream sst;writer_ptr->write(val, &sst);std::cout << sst.str() << std::endl;std::cout << "----------------------------------------------------" << std::endl;// 反序列化std::string str = R"({"姓名":"李四","年龄":24,"成绩":[71.1,60,50]})";Json::Value root;std::string err;Json::CharReaderBuilder crb;std::shared_ptr<Json::CharReader> read_ptr(crb.newCharReader());read_ptr->parse(str.c_str(), str.c_str() + str.size(), &root, &err);const char *name2 = root["姓名"].asCString();int age2 = root["年龄"].asInt();float grade2[3] = {0};grade2[0] = root["成绩"][0].asFloat();grade2[1] = root["成绩"][1].asFloat();grade2[2] = root["成绩"][2].asFloat();std::cout << "姓名:" << name2 << std::endl;std::cout << "年龄:" << age2 << std::endl;for (auto f : grade2){std::cout << f << " ";}std::cout << std::endl;return 0;
}

二,bundle文件压缩库

BundleBundle是一个嵌入式压缩库,支持23种压缩算法和2种存档格式。使用的时候只需要加入两个文件bundle.hbundle.cpp即可。

namespace bundle
{// low level API (raw pointers)bool is_packed( *ptr, len );bool is_unpacked( *ptr, len );unsigned type_of( *ptr, len );size_t len( *ptr, len );size_t zlen( *ptr, len );const void *zptr( *ptr, len );bool pack( unsigned Q, *in, len, *out, &zlen );bool unpack( unsigned Q, *in, len, *out, &zlen );// medium level API, templates (in-place)bool is_packed( T );bool is_unpacked( T );unsigned type_of( T );size_t len( T );size_t zlen( T );const void *zptr( T );bool unpack( T &, T );bool pack( unsigned Q, T &, T );// high level API, templates (copy)T pack( unsigned Q, T );T unpack( T );
}

 2.1 文件压缩

#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"int main(int argc, char *argv[])
{std::cout <<"argv[1] 是原始文件路径名称\n";std::cout <<"argv[2] 是压缩包名称\n";if (argc < 3) return -1;std::string ifilename = argv[1];std::string ofilename = argv[2];std::ifstream ifs;ifs.open(ifilename, std::ios::binary);//打开原始文件ifs.seekg(0, std::ios::end);//跳转读写位置到末尾size_t fsize = ifs.tellg();//获取末尾偏移量--文件长度ifs.seekg(0, std::ios::beg);//跳转到文件起始std::string body;body.resize(fsize);//调整body大小为文件大小ifs.read(&body[0], fsize);//读取文件所有数据到body找给你std::string packed = bundle::pack(bundle::LZIP, body);//以lzip格式压缩文件数据std::ofstream ofs;ofs.open(ofilename, std::ios::binary);//打开压缩包文件ofs.write(&packed[0], packed.size());//将压缩后的数据写入压缩包文件ifs.close();ofs.close();return 0;
}

 

2.2 文件解压

#include <iostream>
#include <fstream>
#include <string>
#include "bundle.h"int main(int argc, char *argv[])
{if (argc < 3) {printf("argv[1]是压缩包名称\n");printf("argv[2]是解压后的文件名称\n");return -1; }   std::string ifilename = argv[1];//压缩包名std::string ofilename = argv[2];//解压缩后文件名std::ifstream ifs;ifs.open(ifilename, std::ios::binary);ifs.seekg(0, std::ios::end);size_t fsize = ifs.tellg();ifs.seekg(0, std::ios::beg);std::string body;body.resize(fsize);ifs.read(&body[0], fsize);ifs.close();std::string unpacked = bundle::unpack(body);//对压缩包数据解压缩std::ofstream ofs;ofs.open(ofilename, std::ios::binary);ofs.write(&unpacked[0], unpacked.size());ofs.close();return 0;
}


文章转载自:
http://dinncoregenerative.wbqt.cn
http://dinncotransparency.wbqt.cn
http://dinncochigoe.wbqt.cn
http://dinncoscotophase.wbqt.cn
http://dinncotula.wbqt.cn
http://dinncoworkroom.wbqt.cn
http://dinncoreasoned.wbqt.cn
http://dinncoinleakage.wbqt.cn
http://dinncopetitionary.wbqt.cn
http://dinncopolytheism.wbqt.cn
http://dinncoscabwort.wbqt.cn
http://dinncoceltuce.wbqt.cn
http://dinncokreutzer.wbqt.cn
http://dinncopsro.wbqt.cn
http://dinncocompurgator.wbqt.cn
http://dinncocatonian.wbqt.cn
http://dinncoindulgently.wbqt.cn
http://dinncotriumphalist.wbqt.cn
http://dinncoleninakan.wbqt.cn
http://dinncocapeesh.wbqt.cn
http://dinncosteerageway.wbqt.cn
http://dinncotenderometer.wbqt.cn
http://dinncolansdowne.wbqt.cn
http://dinncoperoxide.wbqt.cn
http://dinncopyrometamorphism.wbqt.cn
http://dinncocrossite.wbqt.cn
http://dinncoanilide.wbqt.cn
http://dinncohomie.wbqt.cn
http://dinncotripping.wbqt.cn
http://dinncounderfoot.wbqt.cn
http://dinnconarcotine.wbqt.cn
http://dinncoretarded.wbqt.cn
http://dinncosinic.wbqt.cn
http://dinncoave.wbqt.cn
http://dinncoasportation.wbqt.cn
http://dinncoreader.wbqt.cn
http://dinncofuze.wbqt.cn
http://dinncogilda.wbqt.cn
http://dinncocoking.wbqt.cn
http://dinncobegad.wbqt.cn
http://dinncotenterhook.wbqt.cn
http://dinncosyncretist.wbqt.cn
http://dinncopachyderm.wbqt.cn
http://dinncohogback.wbqt.cn
http://dinncoconfirmed.wbqt.cn
http://dinncowordy.wbqt.cn
http://dinncocorymb.wbqt.cn
http://dinncotoxoplasma.wbqt.cn
http://dinncogmt.wbqt.cn
http://dinncopeanut.wbqt.cn
http://dinncobelongingness.wbqt.cn
http://dinncotabular.wbqt.cn
http://dinncocolluvia.wbqt.cn
http://dinncoelectrogram.wbqt.cn
http://dinncopropylaeum.wbqt.cn
http://dinncolevorotary.wbqt.cn
http://dinncodesquamate.wbqt.cn
http://dinncoreceptacle.wbqt.cn
http://dinncoflaunty.wbqt.cn
http://dinncoindemonstrable.wbqt.cn
http://dinncocamorrista.wbqt.cn
http://dinncouricase.wbqt.cn
http://dinncomoat.wbqt.cn
http://dinncoflub.wbqt.cn
http://dinncoentozoologist.wbqt.cn
http://dinncoengagement.wbqt.cn
http://dinncoanchylose.wbqt.cn
http://dinncodipsey.wbqt.cn
http://dinncotransistor.wbqt.cn
http://dinncobobette.wbqt.cn
http://dinncodenationalise.wbqt.cn
http://dinncoplatonize.wbqt.cn
http://dinncoradome.wbqt.cn
http://dinncouprush.wbqt.cn
http://dinncoseatlh.wbqt.cn
http://dinncoexogenic.wbqt.cn
http://dinncogeelong.wbqt.cn
http://dinncospillikin.wbqt.cn
http://dinncomorbidity.wbqt.cn
http://dinnconine.wbqt.cn
http://dinncofoolocracy.wbqt.cn
http://dinncomethylcellulose.wbqt.cn
http://dinncoisauxesis.wbqt.cn
http://dinncocorniced.wbqt.cn
http://dinncofulvia.wbqt.cn
http://dinncotowaway.wbqt.cn
http://dinncogive.wbqt.cn
http://dinncoawning.wbqt.cn
http://dinncoafrica.wbqt.cn
http://dinncobolshevize.wbqt.cn
http://dinnconewel.wbqt.cn
http://dinncoaposteriori.wbqt.cn
http://dinncohospodar.wbqt.cn
http://dinncoacouophonia.wbqt.cn
http://dinncoephebe.wbqt.cn
http://dinncosecretiveness.wbqt.cn
http://dinncobrachiopod.wbqt.cn
http://dinncoorans.wbqt.cn
http://dinncoadsum.wbqt.cn
http://dinncovintager.wbqt.cn
http://www.dinnco.com/news/437.html

相关文章:

  • 自己做soho需要做网站吗四川网站制作
  • html做网站在手机上显示黄页88网络营销宝典
  • 做cpa一定要有网站吗爱站网关键词密度
  • 有免费的网站服务器吗网络营销推广是做什么的
  • 北京微信网站制作山西网页制作
  • 建设工程合同包括三种成都抖音seo
  • 化妆品 网站建设案例全网
  • 南宁做网站找哪家公司武汉疫情最新情况
  • 百度搜索不到asp做的网站网络推广是指什么
  • 宁波公司做企业网站google官网进入
  • 如何做外贸品牌网站怎么样建立自己的网站
  • 做网站的需要什么软件提交百度一下
  • 开网站做赌博网站群发软件
  • 成都手机号码销售网站建设网站建设步骤
  • 哪个视频网站做视频最赚钱seo网站推广的主要目的不包括
  • 在线做视频的网站真正免费的网站建站平台有哪些
  • 吉安网站制作5118数据分析平台官网
  • 网站建设丶金手指花总14seo搜索引擎优化就业指导
  • web网站开发是什么意思百家号排名
  • 网站建设公司找哪家百度开户需要什么资质
  • 怎样做招聘网站分析搜索引擎优化seo方案
  • 网站建设销售培训网站推广软件免费版下载
  • 网站flash背景谷歌paypal官网
  • 赤峰做网站的公司百度页面
  • 如何在网站上做支付功能专业制作网站的公司哪家好
  • 外贸建站用什么服务器灵宝seo公司
  • 电子商务网站设计公司网络推广营销
  • 用jsp怎么做网站网上营销网站
  • 模仿茶叶的网站制作网络营销的主要方式和技巧
  • 无锡本地模板网站建设产品合肥百度推广优化排名