zoukankan      html  css  js  c++  java
  • mormot生成和解析json

    mormot生成和解析json

    delphi7测试并通过。

    unit Unit1;
    
    interface
    
    uses
      syncommons, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
      Forms, Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    //解析json
    var
      js: TDocVariantData;
      json: string;
    begin
      json := '{"tt":"1"}';
      js.InitJSON(json);
      Caption := js.GetValueByPath(['tt']);
    end;
    (*
    {
      "blockCount":3,
      "blocks":[
        {"FieldCount":1, "fields":[{"Name":"姓名", "Value":["张1", "张2","张三"]}]},
        {"FieldCount":1, "fields":[{"Name":"单位", "Value":["华2", "张2","张三"]}]},
        {"FieldCount":1, "fields":[{"Name":"单位", "Value":["华拓", "张2","张三"]}]} 
      ]
    }
    *)
    
    procedure TForm1.Button2Click(Sender: TObject);
    //解析json
    var
      js, js2, js3: TDocVariantData;
    begin
      js.InitJSONFromFile('tt.json');
      caption := DocVariantData(js.GetValueByPath(['blocks'])).value[0]; //{"FieldCount":1, "fields":[{"Name":"姓名", "Value":["张1", "张2","张三"]}]}
      js2.InitJSON(caption);
      caption := DocVariantData(js2.GetValueByPath(['fields'])).value[0]; //{"Name":"姓名", "Value":["张1", "张2","张三"]}
      js3.InitJSON(caption);
      Caption := js3.U['Name'] + DocVariantData(js3.GetValueByPath(['Value'])).value[0]; //姓名张1
      caption := DocVariantData(DocVariantData(js.A['blocks'].Value[1]).A['fields'].Value[0]).A['Value'].Value[0]; //华2
    end;
    (*
    {"Name":"Str0","Age":0,"List":[1,"Hello",5,{"name":"咏南中间件","age":99}]}
    {"Name":"Str1","Age":1,"List":[1,"Hello",5,{"name":"咏南中间件","age":99}]}
    *)
    procedure TForm1.Button3Click(Sender: TObject);
    //生成json
    var
      jo: Variant;
      i: Int64;
    begin
      TDocVariant.New(jo);
      i := 0;
      while i < 2 do
      begin
        jo.Name := 'Str' + IntToStr(i);
        jo.Age := i;
        jo.List := _JSon('[1,"Hello",5,{"name":"咏南中间件","age":99}]');
        Memo1.Lines.Add(VariantSaveJSON(jo));
        inc(i);
      end;
    end;
    
    end.
    

      

      

  • 相关阅读:
    YCSB测试Mysql,MongoDB,TokuMX,Couchbase性能
    使用FIO对SATA、SSD和PCIe Flash进行测试
    使用jenkins实现持续集成
    linux服务器性能(网卡流量、CPU、内存、磁盘使用率)监控
    Linux下Hadoop2.7.1集群环境的搭建(超详细版)
    10分钟学会js处理json常用方法
    springboot:Java模板引擎Thymeleaf介绍
    springboot使用遇到问题:Class “model.Address” is listed in the persistence.xml file but not mapped
    eclipse4.6.1安装SpringSource Tool Suite(sts-eclipse)插件
    由一条sql语句想到的子查询优化
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/14827165.html
Copyright © 2011-2022 走看看