廣告

2024 年 4 月
1234567
891011121314
15161718192021
22232425262728
2930  

彙整

DELPHI使用lkJSON多層次一般取值與陣列取值範例

文章出處
http://rakelitica.blogspot.com/2012/07/using-lkjson-example-with-google-drive.html

JSON文件範本(可貼到 https://jsoneditoronline.org/#left=local.lapedo&right=local.vaxeha 幫你線上格式化JSON比較好看懂)

{
  "kind": "drive#fileList",
  "etag": "\"ia2FS23424234234ANFYAdsc1Tyua2KKA-HnMs\"",
  "selfLink": "
https://www.googleapis.com/drive/v2/files",
  "items": [
  {
   "kind": "drive#file",
   "id": "0BwtHRVB3TFRHVllvRVE",
   "etag": "\"ia2H5NSXK_wk/MTM0MTc3MTMwMTU5Mg\"",
   "selfLink": "
https://www.googleapis.com/drive/v2/files/0BwPgllvRVE",
   "alternateLink": "
https://docs.google.com/folder/d/0BwPgllvRVE/edit",
   "permissionsLink": "
https://www.googleapis.com/drive/v2/files/0BwPgllvRVE/permissions",
   "title": "Folder0",
   "mimeType": "application/vnd.google-apps.folder",
   "description": "Folzer Zero",
   "labels": {
    "starred": false,
    "hidden": false,
    "trashed": false,
    "restricted": false,
    "viewed": true
   },
   "createdDate": "2012-07-08T18:13:51.185Z",
   "modifiedDate": "2012-07-08T18:15:01.592Z",
   "modifiedByMeDate": "2012-07-08T18:15:01.592Z",
   "lastViewedByMeDate": "2012-07-08T18:15:07.039Z",
   "parents": [
     {
     "kind": "drive#parentReference",
     "id": "0AAPgHUk9PVA",
     "selfLink": "
https://www.googleapis.com/drive/v2/files/0BwPgllvRVE1/parents/0AA6_KcYtHUk9PVA",
     "parentLink": "
https://www.googleapis.com/drive/v2/files/0AA6_KcYtHUk9PVA",
     "isRoot": true
    }
   ],
   "userPermission": {
    "kind": "drive#permission",
    "etag": "\"ia2FSHMEjvcFQvtI4rH3hoJimnEgfM\"",
    "id": "current",
    "role": "owner",
    "type": "user"
   },
   "quotaBytesUsed": "0",
   "ownerNames": [
    "Artur"
   ],
   "lastModifyingUserName": "Artur",
   "editable": true,
   "writersCanShare": true
  },
  {
   "kind": "drive#file",
  }
  {
   "kind": "drive#file",
  }
  ]
}

DELPHI JSON lkJSON 程式範例

procedure TForm1.BlaBlaBla( JSonString : string );
var
  js,
  itjs: TlkJSONobject;

  ii  : integer;
  Str : string;

  Trash : boolean;
begin

  // Parse the String
  js := TlkJSON.ParseText( JSonString ) as TlkJsonObject;

  // Values on the first level are as easy as this
  selfLink := js.getString( ‘selfLink’ );

  // let’s digg into each document …
  for ii:=0 to js.Field[‘items’].Count-1 do
    begin

    // each document is a TlkJSONobject …
    ijs := (js.Field[‘items’].Child[ ii ] as TlkJSONobject);

    // So, it will be so simple to get something like this…
    Item.etag         := ijs.getString( ‘etag’ );
    Item.Id           := ijs.getString( ‘id’ );
    Item.title        := ijs.getString( ‘title’ );
     
    // Or a little bit different…   
    Item.IsTrash      := ijs[‘labels’].Field[‘trashed’].Value;

    end;

  js.Free;
end

讀者也會看的其它文章:

    Comments are closed.