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.
    

      

      

  • 相关阅读:
    重点---版本问题-Spark中的一次ClassNotFoundException排除
    SPARK-SQL内置函数之时间日期类
    [Spark SQL]Spark SQL读取Kudu,写入Hive
    hive和spark读取kudu表
    解决spark on yarn每次都传递一堆jars的问题
    Spark on YARN
    blocking IO, non-blocking IO, asychronous IO, sychronous IO
    使用set和vector去重(copy函数)
    vector元素去重uninque函数,erase函数
    copy与iterator头文件
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/14827165.html
Copyright © 2011-2022 走看看