从响应中获取值 Json
GET Value from restresponse Json
有什么方法可以从此 JSON 中检索 url
密钥?
{
"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 来检索它。
首先阅读 Embarcadero 的 JSON documentation. You can use the classes in the 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;
或者,如果您使用的是 Embarcadero 的 REST client library,它可以为您检索和预解析 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;
有什么方法可以从此 JSON 中检索 url
密钥?
{
"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 来检索它。
首先阅读 Embarcadero 的 JSON documentation. You can use the classes in the 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;
或者,如果您使用的是 Embarcadero 的 REST client library,它可以为您检索和预解析 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;