首页 > 其他分享 >delphi 自带的JSON序列化类

delphi 自带的JSON序列化类

时间:2023-08-09 17:14:14浏览次数:50  
标签:Arr AB end delphi Vcl JSON var stringValue 序列化

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  System.JSON.Serializers, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
type
  TRecA = record
    stringValue: string;
    datetimeValue: TDateTime;
    integerValue: Integer;
    doubleValue: Double;
  end;

  TRecB = record
    stringValue: string;
    datetimeValue: TDateTime;
    integerValue: Integer;
    doubleValue: Double;
  end;

  TRecAB = record
    A: TRecA;
    B: TRecB;
  end;
begin
  var AB: TRecAB;
  AB.A.stringValue := 'hello world';
  AB.A.datetimeValue := Now;
  AB.A.integerValue := 123;
  AB.A.doubleValue := 3.1415926;

  AB.B.stringValue := 'HELLO WORLD';
  AB.B.datetimeValue := Now;
  AB.B.integerValue := 666;
  AB.B.doubleValue := 3.1415927;

  var Arr: TArray<TRecAB>;

  SetLength(Arr, 1);

  Arr[0] := AB;

  var s := TJsonSerializer.Create;
  Memo1.Text := s.Serialize<TArray<TRecAB>>(Arr);

  var d := TJsonSerializer.Create;
  var EmptyArray: TArray<Integer> := d.Deserialize<TArray<Integer>>('[]');
  Caption := Length(EmptyArray).ToString;
end;

end.

记不清什么时候有的,个人感觉还是很好用的. 可以控制 序列化属性,字段(私有)等。

标签:Arr,AB,end,delphi,Vcl,JSON,var,stringValue,序列化
From: https://www.cnblogs.com/Jiaojiawang/p/17617360.html

相关文章

  • 快速了解JavaScript的JSON
    JSON是用于存储和传输数据的格式。JSON通常用于服务端向网页传递数据。1什么是JSON?JSON英文全称 JavaScript Object NotationJSON是一种轻量级的数据交换格式。JSON是独立的语言 *JSON易于理解。2JSON语法基本上JSON对象就是基于JavaScript对象,因......
  • Weblogic WLS Core Components 反序列化命令执行漏洞(CVE-2018-2628)
    Vulhub-Docker-Composefileforvulnerabilityenvironment1、介绍名称:WeblogicWLSCoreComponents反序列化命令执行漏洞(CVE-2018-2628)编号:CVE-2018-2628原理:应用:Weblogic 版本:Weblogic10.3.6.0,Weblogic12.1.3.0,Weblogic12.2.1.2,Weblogic12.2.1.32、测试2.......
  • NETCORE - 读取 appsettings.json 配置数据
    NETCORE-读取appsettings.json配置数据 环境:net6 webapi 1. 配置appsettings.json数据{"Logging":{"LogLevel":{"Default":"Information","Microsoft.AspNetCore":"Warn......
  • Jackson —— json转换工具
    一、介绍1.一个可以实现JSON字符串和Java对象进行转换的工具类2.转换的核心类是ObjectMapper 二、ObjectMapper常用的两个方法方法名称说明publicStringwriteValueAsString(Objectobj)将一个对象转换为json字符串publicTreadValue(Stringjson,Classclaz......
  • java解析json
    {"status":0,"message":"ok","total":2,"results":[{"name":"蓝光COCO金沙","location":{"lat":30.68754......
  • - 前后端数据传输的编码格式(contentType) - Ajax朝后端提交文件数据 - Ajax朝后端提
    前后端数据传输的编码格式(contentType)前后端数据传输的请求方式有两种:get、post我们只研究post请求的编码格式三种编码格式urlencodedform-datajson发送post请求的方式form表单Ajaxpostman(第三方工具,需要下载) form表单发送post请求的时候数据的编码格式请求头conten......
  • 软件测试|json.decoder.JSONDecodeError: Expecting ‘,‘错误解决
    在处理JSON数据时,有时可能会遇到"json.decoder.JSONDecodeError:Expecting','"的错误,如下图的情况,本文将介绍这个错误的原因以及一些常见的解决方法。错误原因"json.decoder.JSONDecodeError:Expecting','"错误通常发生在解析JSON数据时,Python解析器期望在JSON对象或数组的元素......
  • ef使用json类型无法触发更新排查
    一.问题背景  首先诸位请看以上代码,不知道有没有发现什么问题?321 集成流的配置,目前是使用json结构,保存到数据库中的。当初加这个的时候就有发现,没有写update不更新,但是当初因为一些原因,没有主动去深究这个问题,而是手动补了一行update去触发更新。这几天在调整集成......
  • json web token(jwt)详解
    1.jsonwebtoken是什么?JSONWebToken(JWT)是一个开放标准(RFC7519),它定义了一种紧凑的、自包含的方式,用于作为JSON对象在各方之间安全地传输信息。该信息可以被验证和信任,因为它是数字签名的。 2.什么时候你应该用JSONWebTokens下列场景中使用JSONWebToken是......
  • DataFrame 按行转json数据
    importpandasaspd#创建示例DataFramedata={'Name':['Alice','Bob','Charlie'],'Age':[25,30,35],'Occupation':['Engineer','Teacher','Doctor']......