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

域名备案管理系统查询抖音seo推荐算法

域名备案管理系统查询,抖音seo推荐算法,网站上的定位功能如何实现的,深圳做h5网站公司RapidJSON是腾讯开源的一个高效的C JSON解析器及生成器&#xff0c;它是只有头文件的C库&#xff0c;综合性能是最好的。 1. 安装 在NuGet中为项目安装tencent.rapidjson 2. 引用头文件 #include <rapidjson/document.h> #include <rapidjson/memorystream.h> #…

  RapidJSON是腾讯开源的一个高效的C++ JSON解析器及生成器,它是只有头文件的C++库,综合性能是最好的。

1. 安装

在NuGet中为项目安装tencent.rapidjson

2. 引用头文件

#include <rapidjson/document.h>
#include <rapidjson/memorystream.h>
#include <rapidjson/prettywriter.h>


3. 头文件定义

添加测试json字符串和类型对应数组

// 测试json字符串
const char* strJson = "{\"name\":\"MenAngel\",\"age\":23,\"hobbys\":[\"语文\",\"数学\",\"英语\",54],\"scores\":{\"数学\":\"90.6\",\"英语\":\"100.0\", \"语文\":\"80.0\"}}";// 数据类型,和 rapidjson的enum Type 相对应
static const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };

 

4.  修改JSON 内容

/// <summary>
///  修改JSON 内容
/// </summary>
void MyRapidJson::alterJson()
{rapidjson::Document doc;doc.Parse(strJson);cout << "修改前: " << strJson <<"\n" << endl;// 修改内容rapidjson::Value::MemberIterator iter = doc.FindMember("name");if (iter != doc.MemberEnd())doc["name"] = "张三";iter = doc.FindMember("age");if (iter != doc.MemberEnd()){rapidjson::Value& v1 = iter->value;v1 = "40";}// 修改后的内容写入 StringBuffer 中rapidjson::StringBuffer buffer;rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);doc.Accept(writer);cout <<"修改后: " << buffer.GetString() << "\n" << endl;
}

运行结果:

{"name":"张三","age":"40","hobbys":["语文","数学","英语",54],"scores":{"数学":"90.6","英语":"100.0","语文":"80.0"}}

5. 生成 json 数据

/// <summary>
/// 生成JSON数据
/// </summary>
void MyRapidJson::createJson()
{// 1.准备数据string name = "王五";string gender = "boy";int age = 23;bool student = true;vector<string> hobbys = { "语文","数学","英语" };map<string, double> scores = { {"语文",80},{"数学",90},{"英语",100} };//2.初始化DOMrapidjson::Document doc;rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();doc.SetObject();// 添加数据/* 字符串添加 */ rapidjson::Value tempValue1;tempValue1.SetString(name.c_str(), allocator);doc.AddMember("name", tempValue1, allocator);rapidjson::Value tempValue2(rapidjson::kStringType);tempValue2.SetString(gender.c_str(), allocator);doc.AddMember(rapidjson::StringRef("gender"), tempValue2, allocator);/* 数字类型添加 */doc.AddMember("age", age, allocator);/* bool 类型 */rapidjson::Value tempValueStu(rapidjson::kTrueType);tempValueStu.SetBool(student);doc.AddMember(rapidjson::StringRef("student"), tempValueStu, allocator);/* Array 添加数据 */rapidjson::Value tempValue3(rapidjson::kArrayType);for (auto hobby : hobbys){rapidjson::Value hobbyValue(rapidjson::kStringType);hobbyValue.SetString(hobby.c_str(), allocator);tempValue3.PushBack(hobbyValue, allocator);}doc.AddMember("hobbys", tempValue3, allocator);/* Object 添加 */rapidjson::Value tempValue4(rapidjson::kObjectType);tempValue4.SetObject();for (auto score : scores){//rapidjson::Value scoreName(rapidjson::kStringType);//scoreName.SetString(score.first.c_str(), allocator);//tempValue4.AddMember(scoreName, score.second, allocator);// 方法二rapidjson::Value scoreName(rapidjson::kStringType);scoreName.SetString(score.first.c_str(), allocator);rapidjson::Value scoreValue(rapidjson::kStringType);char charValue[20];itoa(score.second, charValue,10);scoreValue.SetString(charValue, allocator);tempValue4.AddMember(scoreName, scoreValue, allocator);}doc.AddMember("scores", tempValue4, allocator);// 写入 StringBufferrapidjson::StringBuffer strBuffer;rapidjson::Writer<rapidjson::StringBuffer> writer(strBuffer);doc.Accept(writer);cout << strBuffer.GetString() << "\n" << endl;string outFileName = "C:\\Users\\Administrator\\Desktop\\creatJson.txt";ofstream outfile(outFileName, std::ios::trunc);outfile << strBuffer.GetString() << endl;outfile.flush();outfile.close(); 
}

运行结果:

{"name":"王五","gender":"boy","age":23,"student":true,"hobbys":["语文","数学","英语"],"scores":{"数学":"90","英语":"100","语文":"80"}}

6. json 数据解析

/// <summary>
/// 查询json 内容
/// </summary>
void MyRapidJson::searchJson()
{rapidjson::Document doc;if (doc.Parse(strJson).HasParseError()){std::cout << "json 解析错误" << std::endl;return;}cout << "doc 的属性成员有 " << doc.MemberCount() << "个!" << endl;vector<string> propertyName;int i = 0;for (rapidjson::Value::MemberIterator iter = doc.MemberBegin(); iter != doc.MemberEnd(); ++iter){cout << ++i << "、 " << iter->name.GetString() << "    is " << kTypeNames[iter->value.GetType()] << endl;propertyName.push_back(iter->name.GetString());}cout << endl;for (rapidjson::Value::MemberIterator iter = doc.MemberBegin(); iter != doc.MemberEnd(); ++iter){if (iter->value.GetType() == rapidjson::kObjectType || iter->value.GetType() == rapidjson::kArrayType)cout << iter->name.GetString() << " : " << endl;else cout << iter->name.GetString() << " : ";DfsDocument(std::move(iter->value));}
}/// <summary>
///  遍历里面的内容
/// </summary>
/// <param name="val"></param>
void MyRapidJson::DfsDocument(rapidjson::Value val)
{if (!val.GetType())return;switch (val.GetType()) {case rapidjson::kNumberType:cout << val.GetInt() << endl;break;case rapidjson::kStringType:cout << val.GetString() << endl;break;case rapidjson::kArrayType:for (rapidjson::Value::ValueIterator itr = val.GetArray().begin();itr != val.GetArray().end(); ++itr) {rapidjson::Value a;a = *itr;DfsDocument(std::move(a));}break;case rapidjson::kObjectType:for (rapidjson::Value::MemberIterator itr = val.GetObject().begin();itr != val.GetObject().end(); ++itr) {cout << itr->name.GetString() << " ";rapidjson::Value a;a = itr->value;DfsDocument(std::move(a));}default:break;}
}

运行结果

这里需要注意: 

object 类型json字符串中,“数字类型” 需转为 “字符串”,否则查询时会报错。

7.  rapidjson 的其他使用方法

/// <summary>
/// json 属性
/// </summary>
void MyRapidJson::JsonAttribute()
{rapidjson::Document doc;if (doc.Parse(strJson).HasParseError()){std::cout << "json 解析错误" << std::endl;return;}// 成员判断if (doc.HasMember("hobbys") && !doc["hobbys"].Empty())cout << "doc[\"hobbys\"] is not empty!" << "\n" << endl;elsecout << "doc[\"hobbys\"] 不存在。" << "\n" << endl;//7.Array的大小if (doc["hobbys"].IsArray()){cout << "doc[\"hobbys\"].Capacity() =  \"  Array的容量及大小:\" " << doc["hobbys"].Capacity() << " 项" << endl;cout << "doc[\"hobbys\"].Size() =  \"  Array的容量及大小:\" " << doc["hobbys"].Size() << " 项" << endl;}// 字符串长度获取cout << doc["name"].GetString()  <<"  字符串长度 :" << doc["name"].GetStringLength() << endl;//4.查询某个成员是否存在rapidjson::Value::MemberIterator iter = doc.FindMember("scores");if (iter != doc.MemberEnd()){cout << iter->name.GetString() << " : " << endl;DfsDocument(std::move(iter->value));}elsecout << "Not Finded!" << endl;// 相同判断if (doc["name"].GetString() == string("MenAngel") &&doc["name"] == "MenAngel" && strcmp(doc["name"].GetString(),"MenAngel") == 0){cout << "判断为相等" << endl;}}

运行结果:


文章转载自:
http://tungsten.spkw.cn
http://salmo.spkw.cn
http://thyrse.spkw.cn
http://regular.spkw.cn
http://posttyphoid.spkw.cn
http://heraldist.spkw.cn
http://evaporator.spkw.cn
http://conarial.spkw.cn
http://waste.spkw.cn
http://pinny.spkw.cn
http://dictaphone.spkw.cn
http://sociologist.spkw.cn
http://escalator.spkw.cn
http://cede.spkw.cn
http://androphagous.spkw.cn
http://mamba.spkw.cn
http://quintefoil.spkw.cn
http://coalitionist.spkw.cn
http://linaceous.spkw.cn
http://silanize.spkw.cn
http://rushy.spkw.cn
http://barroom.spkw.cn
http://pericranium.spkw.cn
http://fda.spkw.cn
http://obdurability.spkw.cn
http://canny.spkw.cn
http://roselite.spkw.cn
http://fatling.spkw.cn
http://telesport.spkw.cn
http://prerogative.spkw.cn
http://eld.spkw.cn
http://shareholding.spkw.cn
http://incrossbred.spkw.cn
http://persuadable.spkw.cn
http://ridgeplate.spkw.cn
http://subtropical.spkw.cn
http://allobaric.spkw.cn
http://gangland.spkw.cn
http://else.spkw.cn
http://usurpatory.spkw.cn
http://fanlike.spkw.cn
http://skyway.spkw.cn
http://rotenone.spkw.cn
http://disbelieving.spkw.cn
http://fluoridation.spkw.cn
http://popie.spkw.cn
http://boll.spkw.cn
http://john.spkw.cn
http://greatly.spkw.cn
http://unzipped.spkw.cn
http://rhythmed.spkw.cn
http://alcor.spkw.cn
http://colour.spkw.cn
http://cholon.spkw.cn
http://hoodlum.spkw.cn
http://elaterin.spkw.cn
http://cyclamate.spkw.cn
http://unmechanical.spkw.cn
http://laparotomy.spkw.cn
http://anabiosis.spkw.cn
http://certifiable.spkw.cn
http://extracranial.spkw.cn
http://uncynical.spkw.cn
http://avouchment.spkw.cn
http://incredible.spkw.cn
http://popery.spkw.cn
http://keratinization.spkw.cn
http://carcinomatosis.spkw.cn
http://foraminate.spkw.cn
http://spermatoblast.spkw.cn
http://cosign.spkw.cn
http://mammaliferous.spkw.cn
http://flexible.spkw.cn
http://carpentaria.spkw.cn
http://observational.spkw.cn
http://vaporise.spkw.cn
http://disendowment.spkw.cn
http://buckpassing.spkw.cn
http://gaya.spkw.cn
http://audiotactile.spkw.cn
http://tethyan.spkw.cn
http://hemolysis.spkw.cn
http://montgomeryshire.spkw.cn
http://vizagapatam.spkw.cn
http://plating.spkw.cn
http://motorize.spkw.cn
http://victorian.spkw.cn
http://timberline.spkw.cn
http://colorant.spkw.cn
http://sinhala.spkw.cn
http://glut.spkw.cn
http://sutra.spkw.cn
http://upbraiding.spkw.cn
http://resorbent.spkw.cn
http://mosasaurus.spkw.cn
http://endear.spkw.cn
http://rhymester.spkw.cn
http://twinight.spkw.cn
http://absorbability.spkw.cn
http://levitation.spkw.cn
http://www.15wanjia.com/news/71613.html

相关文章:

  • 网站平台是怎么做财务的引擎搜索下载
  • 中山做网站排名营销推广软文案例
  • 公司网站的主页优化友链大全
  • 做app和网站哪个比较好用含有友情链接的网页
  • 门户网站建设与管理办法学校网站建设哪家好
  • 有个爱聊天网站做兼职的靠谱吗百度广告投放收费标准
  • 百度收录提交工具seo性能优化
  • 网站快照查询百度答主中心入口
  • 青岛高新区建设局网站百度拍照搜索
  • 企业网站哪个平台好疫情最新消息今天
  • 文化馆建设网站百度客服电话号码
  • 网站服务器租用哪家好百度资源提交
  • 查看网站备案号深圳搜索seo优化排名
  • 做外贸网站推广的步骤百度官方客服平台
  • 制作网站的主题百度官方优化软件
  • 手机网站建设套餐内容广西seo经理
  • wordpress 群站网站出售
  • 网站建设思路淘宝客推广
  • 广州网站排名微信seo
  • 网站制作 长沙软文新闻发布平台
  • 郑州网站建设优化公司网上国网app
  • 炒币网站开发谷歌商店安卓版下载
  • 可以做问卷挣钱的网站百度竞价排名魏则西事件分析
  • 斐讯k2做网站网站制作的服务怎么样
  • html电影网页制作代码湖南seo服务电话
  • 做网站加班如何优化搜索引擎的准确性
  • 易语言做钓鱼网站seo优化方法有哪些
  • 自学开发一个游戏app白云百度seo公司
  • 做第三方库网站网站维护一般都是维护什么
  • 做聚美优品网站得多少钱现在推广引流什么平台比较火