频道分类

delphi TMS WEB core WebHttpRequest1 解析JSON

作者:admin 来源: 日期:2020/3/13 22:04:42 人气: 标签:TMS WEB core

 {"Result":"OK","Records":[{"id":504},{"id":505},{"id":534},{"id":535},{"id":536}]}

procedure TForm1.WebHttpRequest1Response(Sender: TObject; AResponse: string);
var
  js: TJSON;
  ja: TJSONArray;
  jo: TJSONObject;
  i: integer;
begin
 jo := js.Parse(AResponse);

    ja  := TJSONArray(jo.GetValue('Records'));

    ShowMessage('Retrieved items:' +inttostr(ja.Count));

    for i := 0 to ja.Count - 1 do
    begin
      jo := ja.Items[i];
      WebListBox1.Items.Add(jo.GetJSONValue('id'));
    end;
  finally
    js.Free;
  end;
 end;