Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure TForm2.Button1Click(Sender: TObject);
  2.  
  3. var
  4.  
  5.   Json: TJSONObject;
  6.    result: TJSONArray;
  7.    result1: string;
  8.    result2: string;
  9.    result3: TJSONArray;
  10.   str: string;
  11.   Json1: string;
  12.   i, j: integer;
  13.   str1: string;
  14. begin
  15.  
  16.  
  17.  
  18.   dynRESTcl := TRESTClient.Create('https://search-maps.yandex.ru/v1/?text=' + Edit1.Text);
  19.   dynRESTreq := TRESTRequest.Create(nil);
  20.   dynRESTresp := TRESTResponse.Create(nil);
  21.   dynRESTreq.Client := dynRESTcl;
  22.   dynRESTreq.Response := dynRESTresp;
  23.  
  24.   dynRESTreq.Method := TRESTRequestMethod.rmGET;
  25.   dynRESTcl.AcceptCharset := 'UTF-8, *;q=0.8';
  26.   dynRESTcl.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,';
  27.   dynRESTreq.Params.AddItem('type', 'biz', TRESTRequestParameterKind.pkGETorPOST);
  28.   dynRESTreq.Params.AddItem('lang', 'ru_RU', TRESTRequestParameterKind.pkGETorPOST);
  29.   dynRESTreq.Params.AddItem('apikey', 'd668c861-f944-473c-88b8-ca7992396ff1', TRESTRequestParameterKind.pkGETorPOST);
  30.  
  31.   dynRESTreq.Execute;
  32.  
  33.   str := dynRESTresp.Content;
  34.   Memo1.Lines.Add(str);
  35.  
  36.  
  37.    if (ContainsText(str, 'features') and ContainsText(str, 'name')) then begin
  38.      Json := TJSONObject.ParseJSONValue(str) as TJSONObject;
  39.      if not Assigned(JSON) then  raise Exception.Create('Файл не содержит JSON-данные');
  40.  
  41.      result := (JSON.Get('features').JsonValue as TJSONArray);
  42.      result1 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('name').JsonValue.Value;
  43.      result2 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('address').JsonValue.Value;
  44.      result3 := (((result.Get(0) as TJSONObject).Get('properties').JsonValue as TJSONObject).Get('CompanyMetaData').JsonValue as TJSONObject).Get('Categories').JsonValue as TJSONArray;
  45.      showmessage(result1);
  46.      showmessage(result2);
  47.  
  48.      for j := 0 to result3.Count-1 do begin
  49.        showmessage((result3.Get(j) as TJSONObject).Get('name').JsonValue.Value);
  50.      end;
  51.  
  52.  
  53.    end else
  54.    showmessage('Не нашел!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement