下面先說一下ISuperObject中幾個經常使用的函數web
下面咱們看一個演示代碼,json數據以下json
{ "retcode": "1", "datafrom": "server", "users": "[{\"id\":1, \"username\": \"liuderu\", \"website\": \"bcoder.com\"},{\"id\":2, \"username\": \"Jeoe\", \"website\": \"baidu.com\"}]" }
Delphi版本2010,代碼以下:數組
unit uFmMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Buttons, superobject; type TFmMain = class(TForm) Memo1: TMemo; ListView1: TListView; BitBtn1: TBitBtn; Label1: TLabel; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var FmMain: TFmMain; implementation {$R *.dfm} procedure TFmMain.BitBtn1Click(Sender: TObject); var jRet, jUsers: ISuperObject; aryUsers: TSuperArray; retCode: integer; strUsers: string; i: integer; begin jRet := SO(Memo1.Text); if (jRet.O['retcode'] <> nil) then begin retCode := jRet.O['retcode'].AsInteger; Label1.Caption := '返回值:' + IntToStr(retCode) + '; 數據來源:' + jRet.O['datafrom'].AsString; if(jRet.O['retcode'].AsInteger = 1) then begin strUsers := jRet.O['users'].AsString; jUsers := SO(strUsers); aryUsers := jUsers.AsArray; for I := 0 to aryUsers.Length - 1 do begin with ListView1.Items.Add do begin Caption := aryUsers[i].O['id'].AsString; SubItems.Add(aryUsers[i].O['username'].AsString); SubItems.Add(aryUsers[i].O['website'].AsString); end; end; end; end; end; end.