JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写,同时也易于机器解析和生成。它基于JavaScript(Standard ECMA-262 3rd Edition - December 1999)的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。这些特性使JSON成为理想的数据交换语言。
Delphi7中不支持JSON文件的解析,可以下载LkJSON(一个JSON的解析文件),然后进行解析。例如
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
memo1: TMemo;
Memo2: TMemo;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses uLkJSON,PerlRegEx;
{$R *.dfm}
procedure listarray(returnval: string; memo: Tmemo);
var
json, item: TlkJSONbase;
i: integer;
list: TlkJSONObject;
str: TlkJSONstring;
begin
json := TlkJSON.ParseText(returnval);
for i := 0 to pred(json.Count) do
begin
item := TlkJSONObject(json).child[i];
// This is the named array, name in name, the array in Objvalue
Memo.Lines.Add(TlkJSONobjectmethod(item).name);
// list:=TlkJSONobject(TlkJSONobjectmethod(item).Objvalue);
end;
end;
procedure getlist(returnval: string; memo: Tmemo);
var
Jstart: TlkJSONbase;
jAddr: TlkJSONList;
s: string;
begin
Jstart := TlkJSON.ParseText(returnval) as TlkJSONobject;
//Jstart.field 为jbase时,
s := vartostr(Jstart.F