mormot2 JSON序列
mormot2 JSON序列
record序列为json,lazarus是buffer的base64字符串,因为lazarus rtti对record支持不全。buffer的base64字符串,对于rest api跨语言开发无疑是致命的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | unit mormot2.json.serial; /// <author>cxg 202371</author> {$IFDEF fpc} {$MODE DELPHI} {$ENDIF} interface uses mormot.core.buffers, mormot.core.text, mormot.core.json, mormot.core. base , Classes, SysUtils; type { TSerial } TSerial = class class function marshal<T>( const aRec: T): rawutf8; overload; class function marshal( const aObj: TObject): rawutf8; overload; class function unmarshal<T>( const json: rawutf8): T; overload; class procedure unmarshal( const json: rawutf8; aObj: TObject); overload; end; implementation { TSerial } class function TSerial.marshal( const aObj: TObject): rawutf8; begin Result := mormot.core.text.ObjectToJson(aObj); end; class function TSerial.marshal<T>( const aRec: T): rawutf8; begin result := mormot.core.json.RecordSaveJson(aRec, TypeInfo(T)); end; class procedure TSerial.unmarshal( const json: rawutf8; aObj: TObject); begin mormot.core.json.ObjectLoadJson(aObj, json); end; class function TSerial.unmarshal<T>( const json: rawutf8): T; begin mormot.core.json.RecordLoadJson(result, json, TypeInfo(T)); end; end. |
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/18101800
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-03-28 QJSON封装好的序列和还原方法
2018-03-28 ADO特有的流化和还原
2017-03-28 Delphi跨平台下的GetTickCount,GetCurrentThreadID
2017-03-28 DELPHI是怎么实现跨平台的?
2017-03-28 DELPHI跨平台编译开关
2017-03-28 DELPHI 10.2(TOKYO) FOR LINUX的兼容性说明
2016-03-28 dxbarmanager生成传统下拉式样的菜单