mormot2.json.serial
unit mormot2.json.serial; /// <author>cxg 2023-2-11</author> {$IFDEF fpc} {$MODE DELPHI}{$H+} {$ENDIF} interface uses mormot.core.text, mormot.core.json, mormot.core.base, Classes, SysUtils; type { TSerial } TSerial = class class function marshal<T>(const aRec: T): rawutf8; class function marshal2(const aObj: TObject): rawutf8; class function unmarshal<T>(const json: rawutf8): T; class procedure unmarshal2(const json: rawutf8; aObj: TObject); end; implementation { TSerial } class function TSerial.marshal2(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.unmarshal2(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/17136907.html