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

自己做链接的网站吗网站开发的概念

自己做链接的网站吗,网站开发的概念,什么官网比较容易做网站,怎么建设商城网站文章目录 一、介绍1.1 json 介绍 二、C/C json 库选型2.1 选型范围2.2 jsoncpp2.2.2 jsoncpp 编译和交叉编译 2.3 rapidjson2.4 nlohmann/json2.5 sonic-cpp 五、常见问题5.1 jsoncpp 中关于浮点数的控制和中文显示问题5.2 jsoncpp序列化double类型时精度损失问题的解决办法 一… 文章目录 一、介绍1.1 json 介绍 二、C/C json 库选型2.1 选型范围2.2 jsoncpp2.2.2 jsoncpp 编译和交叉编译 2.3 rapidjson2.4 nlohmann/json2.5 sonic-cpp 五、常见问题5.1 jsoncpp 中关于浮点数的控制和中文显示问题5.2 jsoncpp序列化double类型时精度损失问题的解决办法 一、介绍 1.1 json 介绍 官网http://www.json.org/json-zh.htmlJSON是什么如何正确理解 二、C/C json 库选型 2.1 选型范围 资料 官网http://www.json.org/json-zh.html开源库比较https://github.com/miloyip/nativejson-benchmarkC中json库的选择C/C 开源 JSON 程序库性能及标准符合程度评测 开源库 Rapidjson、Rapidjson_FullPrec、Rapidjson_AutoUTFnlohmann / jsonjsoncpp 结论 注重最佳性能选 Rapidjson (cereal序列化库使用)注重易用性选 jsoncpp ros 使用、nlohmann / json 2.2 jsoncpp 精度控制precision 15,16,17原值会变0-14原值不变的情况下四舍五入 2.2.2 jsoncpp 编译和交叉编译 jsoncpp 的编译和交叉编译 编译 mkdir build; cd build cmake -DCMAKE_BUILD_TYPERelease \ -DBUILD_SHARED_LIBSON \ -DCMAKE_INSTALL_PREFIXpwd/result \ -DJSONCPP_WITH_TESTSOFF \ .. make install -j4交叉编译 mkdir build; cd build cmake -DCMAKE_BUILD_TYPERelease \ -DBUILD_SHARED_LIBSON \ -DCMAKE_INSTALL_PREFIXpwd/result \ -DJSONCPP_WITH_TESTSOFF \ .. -DCMAKE_TOOLCHAIN_FILEtoolchain.cmake \ .. make install -j4# toolchain.cmake 定义交叉编译环境变量 SET(CMAKE_SYSROOT /opt/fslc-x11/2.4.4/sysroots/armv7at2hf-neon-fslc-linux-gnueabi) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(TOOLS /opt/fslc-x11/2.4.4/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi) set(CMAKE_C_COMPILER ${TOOLS}/arm-fslc-linux-gnueabi-gcc) set(CMAKE_CXX_COMPILER ${TOOLS}/arm-fslc-linux-gnueabi-g) set(CMAKE_AR ${TOOLS}/arm-fslc-linux-gnueabi-ar)include/json lib/cmake/xxx.cmake lib/pkgconfig/jsoncpp.pc pkgconfig mayuePC-MAYUE:/mnt/d/hik/opensource/jsoncpp-1.9.5/build/result/lib$ cat pkgconfig/jsoncpp.pc prefix/mnt/d/hik/opensource/jsoncpp-1.9.5/build/result exec_prefix/mnt/d/hik/opensource/jsoncpp-1.9.5/build/result libdir${exec_prefix}/lib includedir${prefix}/includeName: jsoncpp Description: A C library for interacting with JSON Version: 1.9.5 URL: https://github.com/open-source-parsers/jsoncpp Libs: -L${libdir} -ljsoncpp Cflags: -I${includedir}指定连接静态库 g jsoncpp-test.cpp -I./include -L ./lib -l:libjsoncpp.a2.3 rapidjson http://rapidjson.org/ 2.4 nlohmann/json https://github.com/nlohmann/jsonnlohmann入门使用总结 2.5 sonic-cpp 当前仅支持amd64开源 C JSON 库 sonic-cpp解析性能为 rapidjson 的 2.5 倍性能提升 2.5 倍字节开源高性能 C JSON 库 sonic-cpp 五、常见问题 5.1 jsoncpp 中关于浮点数的控制和中文显示问题 jsoncpp 中关于浮点数的控制和中文显示问题 5.2 jsoncpp序列化double类型时精度损失问题的解决办法 jsoncpp序列化double类型时精度损失问题的解决办法 解决办法1此法不需要改源码使用StreamWriterBuilder进行序列化 #include json/json.h #include json/writer.h #include iostream #include stringvoid test_precision(int precision) {Json::Value root;root[pi] 3.1415926;root[count] 43.32558674566;Json::StreamWriterBuilder builder;//设置精度 注意这个默认设置的是数字总长度 //如果想设置小数点后的位数需设置precisionType为decimalbuilder.settings_[precision] precision;//设置精度类型 只可设置2种字符串 significant精度位数为数字总长度jsoncpp默认为此类型 decimal精度位数为小数点后的长度builder.settings_[precisionType] decimal;// 设置输出为紧凑格式不带换行和空格builder[commentStyle] None; // 防止输出注释默认就是nonebuilder[indentation] ; // 空字符串表示不缩进std::unique_ptrJson::StreamWriter writer(builder.newStreamWriter());std::ostringstream oss;writer-write(root, oss);std::string jsonText oss.str();// 输出 JSON 字符串std::cout specified precision: precision , content: jsonText std::endl; }int main() {for(int i17; i0; i--){test_precision(i);}return 0; }specified precision: 17, content:{count:43.32558674565999723,pi:3.14159260000000007} specified precision: 16, content:{count:43.3255867456599972,pi:3.1415926000000001} specified precision: 15, content:{count:43.325586745659997,pi:3.1415926} specified precision: 14, content:{count:43.32558674566,pi:3.1415926} specified precision: 13, content:{count:43.32558674566,pi:3.1415926} specified precision: 12, content:{count:43.32558674566,pi:3.1415926} specified precision: 11, content:{count:43.32558674566,pi:3.1415926} specified precision: 10, content:{count:43.3255867457,pi:3.1415926} specified precision: 9, content:{count:43.325586746,pi:3.1415926} specified precision: 8, content:{count:43.32558675,pi:3.1415926} specified precision: 7, content:{count:43.3255867,pi:3.1415926} specified precision: 6, content:{count:43.325587,pi:3.141593} specified precision: 5, content:{count:43.32559,pi:3.14159} specified precision: 4, content:{count:43.3256,pi:3.1416} specified precision: 3, content:{count:43.326,pi:3.142} specified precision: 2, content:{count:43.33,pi:3.14} specified precision: 1, content:{count:43.3,pi:3.1} specified precision: 0, content:{count:43,pi:3}精度控制precision 15,16,17原值会变、四舍五入0-14原值不变的情况下四舍五入 特别注意精度设置一定要大于你需求的精度位数比如需要三位可以设置4位或5位因为最后一位可能会不准做了四舍五入 不足之处 StreamWriterBuilder序列化的字符串是可读形式的就像上面的输出是有换行和缩进的转换效率会比FastWrite低我的服务端代码里其实不需要转换json为可读的更需要的是效率所以还有下面一种方法改FasetWrite源码 解决办法2此法需要改源码使用FastWriter进行序列化 注意需升级jsoncpp到最新版本1.9.5版本 修改源码writer.hFastWriter类新增2个成员变量precision_和precisionType_和成员函数(set_precision和set_precisionType) #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4996) // Deriving from deprecated class #endif class JSON_API FastWriter: public Writer { public:FastWriter();~FastWriter() override default;void enableYAMLCompatibility();/** \brief Drop the null string from the writers output for nullValues.* Strictly speaking, this is not valid JSON. But when the output is being* fed to a browsers JavaScript, it makes for smaller output and the* browser can handle the output just fine.*/void dropNullPlaceholders();void omitEndingLineFeed();public: // overridden from WriterString write(const Value root) override;//设置精度位数void set_precision(unsigned int precision) { precision_ (precision 17)?17:precision; };//设置精度类型 默认为数字总长//入参isDecimal true表示类型为小数点后长度 false表示类型为数字总长void set_precisionType(bool isDecimal) { isDecimal ? (precisionType_ PrecisionType::decimalPlaces) : (precisionType_ PrecisionType::significantDigits); };private:void writeValue(const Value value);String document_;bool yamlCompatibilityEnabled_{false};bool dropNullPlaceholders_{false};bool omitEndingLineFeed_{false};int precision_{ 17 };//精度位数 默认17位PrecisionType precisionType_{ PrecisionType::significantDigits };//精度类型 默认为数字总长 }; #if defined(_MSC_VER) #pragma warning(pop) #endif修改源码json_writer.cpp只修改了1行代码FastWriter::writeValue函数中case realValue的处理中调用的valueToString新增了2个参数传递源码中没有传递用的函数默认值现在传了并且可以通过新增的2个成员函数进行设置 void FastWriter::writeValue(const Value value) {switch (value.type()) {case nullValue:if (!dropNullPlaceholders_)document_ null;break;case intValue:document_ valueToString(value.asLargestInt());break;case uintValue:document_ valueToString(value.asLargestUInt());break;case realValue://这里原先是document_ valueToString(value.asDouble());//因为后2个参数没传所以用的函数默认值即精度位数17精度类型PrecisionType::significantDigits//修改后 现在会传这2个参数具体值可以通过新增加的2个成员函数设置document_ valueToString(value.asDouble(), precision_, precisionType_);break;case stringValue: {// Is NULL possible for value.string_? No.char const* str;char const* end;bool ok value.getString(str, end);if (ok)document_ valueToQuotedStringN(str, static_castsize_t(end - str));break;}case booleanValue:document_ valueToString(value.asBool());break;case arrayValue: {document_ [;ArrayIndex size value.size();for (ArrayIndex index 0; index size; index) {if (index 0)document_ ,;writeValue(value[index]);}document_ ];} break;case objectValue: {Value::Members members(value.getMemberNames());document_ {;for (auto it members.begin(); it ! members.end(); it) {const String name *it;if (it ! members.begin())document_ ,;document_ valueToQuotedStringN(name.data(), name.length());document_ yamlCompatibilityEnabled_ ? : : :;writeValue(value[name]);}document_ };} break;} }需要重新编译库然后demo验证使用的代码 #include json/json.h #include json/writer.h #include iostream #include stringvoid test_precision(int precision) {Json::Value obj;Json::FastWriter write;write.set_precision(precision);write.set_precisionType(true);obj[d] 2.1;obj[d2] 9.111;obj[d3] 9.123456789;auto rtn write.write(obj);std::cout specified precision: precision , rtn: rtn std::endl; }int main() {for(int i17; i0; i--){test_precision(i);}return 0; }specified precision: 17, rtn:{d:2.10000000000000009,d2:9.11100000000000065,d3:9.12345678900000046}specified precision: 16, rtn:{d:2.1000000000000001,d2:9.1110000000000007,d3:9.1234567890000005}specified precision: 15, rtn:{d:2.1,d2:9.111000000000001,d3:9.123456789}specified precision: 14, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 13, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 12, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 11, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 10, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 9, rtn:{d:2.1,d2:9.111,d3:9.123456789}specified precision: 8, rtn:{d:2.1,d2:9.111,d3:9.12345679}specified precision: 7, rtn:{d:2.1,d2:9.111,d3:9.1234568}specified precision: 6, rtn:{d:2.1,d2:9.111,d3:9.123457}specified precision: 5, rtn:{d:2.1,d2:9.111,d3:9.12346}specified precision: 4, rtn:{d:2.1,d2:9.111,d3:9.1235}specified precision: 3, rtn:{d:2.1,d2:9.111,d3:9.123}specified precision: 2, rtn:{d:2.1,d2:9.11,d3:9.12}specified precision: 1, rtn:{d:2.1,d2:9.1,d3:9.1}specified precision: 0, rtn:{d:2,d2:9,d3:9} C json序列化库有哪些哪个性能最好 C中有多种JSON序列化库可供选择包括但不限于以下几种 Rapidjson这是一个非常流行的C JSON库以其高性能著称由腾讯团队开发 。 nlohmann/json这是一个现代的、基于C11的JSON库以其易用性和直观的接口而受到许多C程序员的青睐 。 sonic-cpp由字节跳动STE团队和服务框架团队共同研发的高效JSON库它利用CPU硬件特性和向量化编程大幅提高了序列化和反序列化的性能。据报道其解析性能是rapidjson的2.5倍 。 JsonCpp这是一个成熟的库提供了丰富的功能来处理JSON数据。 simdjson这是一个使用SIMD指令集来加速解析的库它提供了快速的解析性能但不支持修改解析后的JSON结构 。 yyjson这是一个追求解析性能的库使用链表结构但在查找数据时性能较差 。 在这些库中sonic-cpp 被报道为性能最好的库它不仅提供了高效的解析性能还解决了其他一些库的缺点如simdjson和yyjson的问题并支持高效的增删改查操作 。此外sonic-cpp已经在字节跳动的多个核心业务中大规模使用并通过了工程化的考验 。 如果您对性能有极高的要求sonic-cpp可能是一个不错的选择。然而选择哪个库还应考虑其他因素如易用性、社区支持、库的活跃度和维护情况。
http://www.dnsts.com.cn/news/266602.html

相关文章:

  • 微名片网站怎么做架构图在什么网站可以做
  • 描述网站开发的广告词哪个公司的网络比较稳定
  • 自己创业做原公司一样的网站wordpress个人博客实战
  • 兰州酒店网站建设脱发严重是什么原因引起的
  • wangz网站建设做a的网站有哪些
  • 免注册个人网站制作商务网站建设综合实训报告
  • 手表网站app中国最好室内设计公司排名榜
  • 绍兴网站开发石家庄网站建设联系方式
  • 北海市建设局网站网站设计论文参考文献
  • 二级菜单网站如何做伪静态昆明网站建设哪家最好
  • 保洁公司做网站有什么作用制作软件下载
  • 摄影网站怎么做数据库济南网站建设推荐搜点网络NO1
  • 查询域名注册网站成都网站建设 四川冠辰网站建设
  • 长沙网站制作好公司wordpress主机需要多大
  • 外贸营销网站建设公司排名免费的商城网站
  • 宁波汽车网站建设商城网站前台模板
  • A华企网络网站建设河北电子网站建设
  • 惠州网站设计海南省海洋监测预报中心
  • 什么是品牌网站手机网站 禁止缩放
  • 签订网站建设协议应注意事项买域名建网站
  • 河南高端建设网站小程序开发定制开发
  • 甘肃网站建设公司网站提高收录和访问量
  • 重庆建网站搜索快忻科技网站建设seo需求文档
  • 建设部网站 43号文件建设部规范网站
  • 淄博做网站推广哪家好建设工程合同备案网站
  • 企业网站设计多少钱牛商网
  • 网站制作公司业务员网络优化的目的及意义
  • 官网做的好看的网站有哪些时尚手表网站
  • 住房和城乡建设网站 上海wordpress标签路径
  • 南软科技网站开发ipv6网站建设