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 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
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生成传统下拉式样的菜单