-1

Any way to retrieve url key from this JSON?

{
  "data": {
    "is_silhouette": false,
    "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/13178742_10205047662871072_6233795154346712405_n.jpg?oh=194b0150c2325660390490779bf9b942&oe=57C22031&__gda__=1472746057_dc9b0557adc8408840fafb73ed325ef8"
  }
}

It is provided by Facebook's Graph API. I'm using a Rest Library in Delphi 10.0 Seattle to retrieve it.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Alexandre Prazeres
  • 415
  • 1
  • 6
  • 12
  • 2
    http://stackoverflow.com/a/37887564/62576 will give you some suggestions regarding how to get started. We're not a code-writing service. – Ken White Jun 21 '16 at 18:55

1 Answers1

9

Start by reading Embarcadero's JSON documentation. You can use the classes in the System.JSON unit, eg:

uses
  ..., System.JSON;

var
  json: string;
  obj, data: TJSONObject;
  url: string;
begin
  json := ...; // JSON data retrieved from REST server
  obj := TJSONObject.ParseJSONValue(json) as TJSONObject;
  try
    data := obj.Values['data'] as TJSONObject;
    url := data.Values['url'].Value;
  finally
    obj.Free;
  end;
end;

Alternatively, if you are using Embarcadero's REST client library, it can retrieve and pre-parse the JSON for you:

var
  obj, data: TJSONObject;
  url: string;
begin
  RESTRequest1.Execute;
  obj := RESTResponse1.JSONValue as TJSONObject;
  data := obj.Values['data'] as TJSONObject;
  url := data.Values['url'].Value;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770