• lazarus的json


    uses fpjson, jsonparser;一定要usejsonparser单元,才会自动创建handler。

    方法与jsonobject几乎一样,但是没有那么方便,特别是在数组问题。

    也没有LoadFromFile和SaveToFile,需要另外实现,不过带了GetJson函数。

     
    1 Function GetJSON(Const JSON : TJSONStringType;Const UseUTF8 :Boolean =True) : TJSONData;
    2 Function GetJSON(Const JSON : TStream;Const UseUTF8 :Boolean =True) : TJSONData;
     

    fpjson数组的操作

    procedure TForm1.Button1Click(Sender: TObject);
    var
      o: TJsonObject;
      a: TJsonArray;
      o1: TJsonObject;
    
      i: Integer;
    begin
      o := TJsonObject.Create;
      o.Integers['i'] := 123;
      o.Strings['s'] := 'abc';
    
      o.Integers['i'] := 345;
    
      a := TJsonArray.Create();
    
      o1 := TJsonObject.Create;
      o1.Integers['i'] := 11;
      o1.Integers['j'] := 21;
      o1.Integers['k'] := 31;
    
      //添加数组
      a.Add(o1);
    
      o1 := TJsonObject.Create;
      o1.Integers['i'] := 12;
      o1.Integers['j'] := 22;
      o1.Integers['k'] := 32;
    
      //添加数组
      a.Add(o1);
    
      o.Add('a', a);
    
      Memo1.Lines.Add(o.AsJSON);
    
      Memo1.Lines.Add('%d', [o.Arrays['a'].Count]);
    
      //读数组内容
      for i := 0 to o.Arrays['a'].Count - 1 do
      begin
        Memo1.Lines.Add('i=%d,j=%d,k=%d', [o.Arrays['a'].Objects[i].Integers['i'],  o.Arrays['a'].Objects[i].Integers['j'], o.Arrays['a'].Objects[i].Integers['k']    ]);
      end;
    
    
      FreeAndNil(o);
    end;
  • 相关阅读:
    C++ 栈和队列
    epoll 实际使用
    js数组的操作
    nodejs 基本类型和语法
    epoll 简单介绍及例子
    epoll 应用
    linux 查看系统状态方法
    struct stat结构体的详解和用法
    Asp.Net_获取IP地址
    Asp.Net_的传值跟存储值操作
  • 原文地址:https://www.cnblogs.com/Thenext/p/15074724.html
Copyright © 2020-2023  润新知