2016-06-21 34 views
-3

任何方式從這個JSON檢索url密鑰?從restresponse 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" 
    } 
} 

它由Facebook's Graph API提供。我在Delphi 10.0 Seattle中使用Rest Library來檢索它。

+2

的http:// stackoverflow.com/a/37887564/62576會爲您提供一些關於如何入門的建議。我們不是代碼編寫服務。 –

回答

4

從閱讀Embarcadero的JSON documentation開始。您可以在System.JSON單位,例如使用的類:

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; 

或者,如果你正在使用英巴卡迪諾的,它可以爲你檢索和預解析JSON:

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; 
+0

謝謝,我確實表達了自己的錯誤。我已經有了一個代碼來做到這一點,但這不是我想要的。 –

+0

再次感謝您,但是 'obj.Free;' 在關閉應用程序時,會導致EInvalidPointer異常,並顯示消息「無效的指針操作異常」。 –