السلام عليكم
نفس المثال لاكن باستعمال وحدات RESTRequest4D
المثال يعمل على win + android
--------------
نعرف متغير لتنفيد api التى يوفرها الموقع يمكن التسجيل فى الموقع للحصول على your free api key
نضيف الوحدات لتنفيد الامر GET و قرائت المخرجات التى يقدمها الموقع
تنفيد الامر GET
عند الحصول على json نستخرج المعلومات التى نريدها
تنفيد العملية
نفس المثال لاكن باستعمال وحدات RESTRequest4D
المثال يعمل على win + android
--------------
نعرف متغير لتنفيد api التى يوفرها الموقع يمكن التسجيل فى الموقع للحصول على your free api key
PHP كود :
BaseUrl: string;
PHP كود :
uses RESTRequest4D, System.JSON, System.JSON.Readers;
تنفيد الامر GET
كود :
function TForm18.ExecuteGet(sBaseUrl: string): string;
var
LResponse: IResponse;
begin
LResponse := TRequest.New.BaseURL(sBaseUrl)
.Accept('application/json')
.Get;
Result := LResponse.Content;
end;عند الحصول على json نستخرج المعلومات التى نريدها
كود :
function TForm18.ExtractData(JSonData: string): TStringList;
var
JSONValue: TJSONValue;
begin
JSONValue := TJSONObject.ParseJSONValue(JSonData, False, False);
Result := TStringList.Create;
try
if JSONValue is TJSONArray then
//...
else if JSONVAlue is TJSONObject then
begin
Result.Add(JSONValue.GetValue<string>('statusCode'));
Result.Add(JSONValue.GetValue<string>('statusMessage'));
Result.Add(JSONValue.GetValue<string>('ipAddress'));
Result.Add(JSONValue.GetValue<string>('countryCode'));
Result.Add(JSONValue.GetValue<string>('countryName'));
Result.Add(JSONValue.GetValue<string>('regionName'));
Result.Add(JSONValue.GetValue<string>('cityName'));
Result.Add(JSONValue.GetValue<string>('zipCode'));
Result.Add(JSONValue.GetValue<string>('latitude'));
Result.Add(JSONValue.GetValue<string>('longitude'));
Result.Add(JSONValue.GetValue<string>('timeZone'));
end;
finally
JSONValue.Free;
end;
end;تنفيد العملية
كود :
Memo1.Lines := ExtractData(ExecuteGet(BaseUrl));

![[-]](https://delphi4arab.net/forum/D4A2020/collapse.png)