Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm2.Button1Click(Sender: TObject);
- var
- Json: TJSONObject;
- result: TJSONArray;
- result1: string;
- result2: string;
- result3: TJSONArray;
- str: string;
- Json1: string;
- i, j: integer;
- str1: string;
- begin
- dynRESTcl := TRESTClient.Create('https://search-maps.yandex.ru/v1/?text=' + Edit1.Text);
- dynRESTreq := TRESTRequest.Create(nil);
- dynRESTresp := TRESTResponse.Create(nil);
- dynRESTreq.Client := dynRESTcl;
- dynRESTreq.Response := dynRESTresp;
- dynRESTreq.Method := TRESTRequestMethod.rmGET;
- dynRESTcl.AcceptCharset := 'UTF-8, *;q=0.8';
- dynRESTcl.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,';
- dynRESTreq.Params.AddItem('type', 'biz', TRESTRequestParameterKind.pkGETorPOST);
- dynRESTreq.Params.AddItem('lang', 'ru_RU', TRESTRequestParameterKind.pkGETorPOST);
- dynRESTreq.Params.AddItem('apikey', 'd668c861-f944-473c-88b8-ca7992396ff1', TRESTRequestParameterKind.pkGETorPOST);
- dynRESTreq.Execute;
- str := dynRESTresp.Content;
- Memo1.Lines.Add(str);
- if (ContainsText(str, 'features') and ContainsText(str, 'name')) then begin
- Json := TJSONObject.ParseJSONValue(str) as TJSONObject;
- if not Assigned(JSON) then raise Exception.Create('Файл не содержит JSON-данные');
- result := (JSON.Get('features').JsonValue as TJSONArray);
- result1 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('name').JsonValue.Value;
- result2 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('address').JsonValue.Value;
- result3 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('Categories').JsonValue as TJSONArray;
- showmessage(result1);
- showmessage(result2);
- for j := 0 to result3.Count-1 do begin
- showmessage((result3.Get(j) as TJSONObject).Get('name').JsonValue.Value);
- end;
- end else
- showmessage('Не нашел!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement