• DataSet Serialize


    DataSet Serialize

    用于Delphi和Lazarus (FPC)的JSON到数据集和数据集到JSON转换器

    源码下载地址:https://github.com/viniciussanchez/dataset-serialize

    uses DataSet.Serialize;
    数据集序列为json
    var
      LJSONArray: TJSONArray;
      LJSONObject: TJSONObject;  
    begin
      LJSONObject := qrySamples.ToJSONObject(); // 导出单个记录
      LJSONArray := qrySamples.ToJSONArray(); // 导出所有记录 
    end; 
    

      保存和加载数据集的结构

    var
      LJSONArray: TJSONArray;
    begin
      LJSONArray := qrySamples.SaveStructure;
      qrySamples.LoadStructure(LJSONArray, True);
    end;
    

      验证json

    begin
      LJSONArray := qrySamples.ValidateJSON('{"country":"Brazil"}');
    end;
    

      从json加载

    begin
      qrySamples.LoadFromJSON('{"firstName":"Vinicius Sanchez","country":"Brazil"}');
    end;
    

      从JSON修改记录

    begin
      qrySamples.MergeFromJSONObject('{"firstName":"Vinicius","country":"United States"}');
    end;
    

      配置

    • 日期输入为UTC(时区)
    TDataSetSerializeConfig.GetInstance.DateInputIsUTC := True;
    • 导出空值
      TDataSetSerializeConfig.GetInstance.export.ExportNullValues := True;
    • 仅导出可见字段
      TDataSetSerializeConfig.GetInstance.export.ExportOnlyFieldsVisible := True;
    • 将子数据集导出为 JSON 对象(当您只有 1 条记录时)
      TDataSetSerializeConfig.GetInstance.export.ExportChildDataSetAsJsonObject := False;
    • 仅导入可见的字段
      TDataSetSerializeConfig.GetInstance.import.ImportOnlyFieldsVisible := True;
    • 案例名称定义
    // cndNone, cndLower, cndUpper, cndLowerCamelCase, cndUpperCamelCase 
      TDataSetSerializeConfig.GetInstance.CaseNameDefinition := cndLowerCamelCase; 
      
      cndNone:
      [ { "MOB_ICADASTRO":11795,"MOB_EMI_REG":6,"CODIGODOCLIENTE":1,"CDOCUMEN1":"999999" } ]
      
      cndLower:
      [ { "mob_icadastro":11795,"mob_emi_"cododig6": :1,"cdocumen1":"999999" } ]
    
      cndUpper:
      [ { "MOB_ICADASTRO":11795,"MOB_EMI_REG":6,"CODIGODOCLIENTE":1,"CDOCUMEN1":"999999" } ]
    
      cndLowerCamelCase"mobIcadastro":11795,"mobEmiReg":6,"codigodocliente":1,"cdocumen1":"999999" } ] 
    
      cndUpperCamelCase:: 
      [ { "MobIcadastro":11795,"MobEmiReg":6,"Codigodocliente":1 "Cdocumen1":"999999" } ]  

    • 格式日期(导出字段类型等于 ftDate)
      TDataSetSerializeConfig.GetInstance.export.FormatDate := ' YYYY-MM-DD ' ;
    • 格式货币(导出字段类型等于 ftCurrency)
      TDataSetSerializeConfig.GetInstance.export.FormatCurrency := ' 0.00## ' ;
    • 定义数据集前缀
      TDataSetSerializeConfig.GetInstance.DataSetPrefix := [ ' mt ' , ' qry ' ];


     
  • 相关阅读:
    Java的三个基础排序算法(其余将在以后补充)
    Review PHP设计模式之——单例模式
    Mysql忘记密码,重新设置
    PHP加解密相关函数
    http返回状态代码及含义
    符合web标准的网页下拉菜单
    解决MySQL查询不区分大小写
    MYSQL Error 2006HY000:MySQL server has gone away的解决方案
    MySQL之count(*)与count(id)效率比较(转)
    如何让sudo命令不需要输入密码就可执行
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/15138564.html
Copyright © 2020-2023  润新知