zoukankan      html  css  js  c++  java
  • 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;
    

      

  • 相关阅读:
    Android之文件&XML
    Dialog组件
    Android模拟器使用SD卡(2)
    Android 蓝牙开发浅析
    创建和解析XML
    android 读取文件相关
    android 网络编程 HttpGet类和HttpPost类使用详解
    Android模拟器使用SD卡(1)
    Android中控件的OnKeyListener()事件
    [转]Android蓝牙开发浅谈
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/15134085.html
Copyright © 2011-2022 走看看