• fpjson


    fpjson

    fpc官方帮助:https://wiki.freepascal.org/fcl-json

    fcl-json 是一个JSON实现。

    它包含以下单位:

    • fpjson:实现 TJsonData 及其子项的基本单元,例如 TJsonObject
    • jsonParser:实现 TJsonParser,在下面From JsonViewer示例中使用
    • jsonConf:实现了 TJsonConfig,它可以方便地从/向文件读取/写入应用程序数据
    • jsonScanner:json 源码词法分析器
    uses
      fpjson, jsonparser;
    
    procedure JSONTest;
    var
      jData : TJSONData;
      jObject : TJSONObject;
      jArray : TJSONArray;
      s : String;
    begin
      
      // this is only a minimal sampling of what can be done with this API
    
      // create from string
      jData := GetJSON('{"Fld1" : "Hello", "Fld2" : 42, "Colors" : ["Red", "Green", "Blue"]}');
    
      // output as a flat string
      s := jData.AsJSON;
    
      // output as nicely formatted JSON
      s := jData.FormatJSON;
    
      // cast as TJSONObject to make access easier
      jObject := TJSONObject(jData);
    
      // retrieve value of Fld1
      s := jObject.Get('Fld1');
    
      // change value of Fld2
      jObject.Integers['Fld2'] := 123;
    
      // retrieve the second color
      s := jData.FindPath('Colors[1]').AsString;
    
      // add a new element
      jObject.Add('Happy', True);
    
      // add a new sub-array
      jArray := TJSONArray.Create;
      jArray.Add('North');
      jArray.Add('South');
      jArray.Add('East');
      jArray.Add('West');
      jObject.Add('Directions', jArray);
    
    end;
    

      

    uses
      jsonConf;
    
    procedure TfmMain.SaveOptionsPos;
    var
      c: TJSONConfig;
    begin
      c:= TJSONConfig.Create(Nil);
      try
        c.Filename:= GetAppPath(cFileHistory);
        c.SetValue('/dialog/max', WindowState=wsMaximized);
        if WindowState<>wsMaximized then
        begin
          c.SetValue('/dialog/posx', Left);
          c.SetValue('/dialog/posy', Top);
          c.SetValue('/dialog/sizex', Width);
          c.SetValue('/dialog/sizey', Height);
        end;
      finally
        c.Free;
      end;
    end;
    
    procedure TfmMain.LoadOptionsPos;
    var
      nLeft, nTop, nW, nH: Integer;
      c: TJSONConfig;
    begin
      c:= TJSONConfig.Create(Nil);
      try
        c.Filename:= GetAppPath(cFileHistory);
    
        nLeft:= c.GetValue('/dialog/posx', Left);
        nTop:= c.GetValue('/dialog/posy', Top);
        nW:= c.GetValue('/dialog/sizex', Width);
        nH:= c.GetValue('/dialog/sizey', Height);
        SetBounds(nLeft, nTop, nW, nH);
    
        if c.GetValue('/dialog/max', false) then
          WindowState:= wsMaximized;
      finally
        c.Free;
      end;
    end;
    

      

  • 相关阅读:
    linux内核编译
    字符设备驱动ioctl实现用户层内核层通信
    Linux内核完全剖析基于0.12内核
    KVM分析报告
    kvm的vmcall
    kvm源代码分析
    KVM基本概念
    linux系统调用
    UML的9种图例解析(转)
    SurfaceView的基本使用(转)
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/15134085.html
Copyright © 2020-2023  润新知