Einzelnen Beitrag anzeigen

venice2
(Gast)

n/a Beiträge
 
#26

AW: Json unbekanntes feld abfangen

  Alt 16. Dez 2020, 21:39
Hmm das scheint es zu sein.
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
type
  TChannelsData = record
    display_alias: string;
    sharing: BOOL;
    is_radio: BOOL;
    title: string;
    cid: string;
    number: LongInt;
    recording: BOOL;
    success: BOOL;
  end;
var
  s: String;
  i: Integer;
  iRun, nRun: Integer;
  doc: TDocVariantData;
  docChannelGroup: PDocVariantData;
  docChannels: PDocVariantData;
  gChannels: array of TChannelsData;
begin
  doc.InitJSONFromFile('Channels_data.json', JSON_OPTIONS_FAST_EXTENDED);
  if not doc.B['success'] then
    Exit;

  i := 0;
  for iRun := 0 to doc.A['channel_groups'].Count - 1 do
  begin
    docChannelGroup := doc.A['channel_groups']._[iRun];
    for nRun := 0 to docChannelGroup.A['channels'].Count - 1 do
    begin
      docChannels := docChannelGroup.A['channels']._[nRun];
      setLength(gChannels, i + 1);

      gChannels[i].display_alias := docChannels.S['display_alias'];
      gChannels[i].sharing := docChannels.B['sharing'];
      gChannels[i].is_radio := docChannels.B['is_radio'];
      gChannels[i].title := docChannels.S['title'];
      gChannels[i].cid := docChannels.S['cid'];
      gChannels[i].number := docChannels.I['number'];
      gChannels[i].recording := docChannels.B['recording'];

      Inc(i);
    end;
  end;

  ShowMessage(IntToStr(i));
end;
Nochmals Danke

Geändert von venice2 (17. Dez 2020 um 13:05 Uhr)
  Mit Zitat antworten Zitat