AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Json unbekanntes feld abfangen

Ein Thema von venice2 · begonnen am 15. Dez 2020 · letzter Beitrag vom 22. Dez 2020
 
venice2
(Gast)

n/a Beiträge
 
#21

AW: Json unbekanntes feld abfangen

  Alt 16. Dez 2020, 04:26
zur zeit wird der Channel auf diese weise eingelesen.

Delphi-Quellcode:
  // Ignore: '{"channel_groups":'
  // a channel-definition begins with "display_alias": "
  PosNext := PosEx('"display_alias"', Data, 1); // get begin of first channel
  id := 0;
  n := 0;
//Log('UPDCHL', 'LEN: ' + inttostr(length(data)));
  while (PosNext > 0) do
  begin
//LOG('UPDCHL', '------------------------');
    inc(PosNext, 1);
    inc(n);
    Application.ProcessMessages;
    // --- Read all values in order of apperance:
    // "display_alias" - NOZ USED // 1)
    sha := GetBool(posnext, Data, '"sharing": '); // 2)
    rad := GetBool(posnext, Data, '"is_radio": '); // 3)
    tit := GetStr(PosNext, Data, '"title": "', '"'); // 4)
    tit := DecodeJString(tit);
    cid := GetStr(posnext, Data, '"cid": "', '"'); // 5)
//Log('UPDCHL', inttostr(PosNext) + ' | CID: ' + cid);
    num := GetStr(PosNext, Data, '"number": ',','); // 6)
//Log('UPDCHL', inttostr(PosNext) + ' | ZatNum: ' + num + ' | RecNum: ' + inttostr(n));
    // Here: ... EPG-NEXT 7)
    rec := GetBool(posnext, Data, '"recording": '); // 8)
    // --- Check if Channel already exists:
    x := GetChlbyCID(1, cid, ChlRec);
    if (x < 0) then
    begin
      // NOT FOUND !!! New ChlRec
      New(ChlRec); // create a new record:
      id := FCHLList.Add(ChlRec);
//Log('UPDCHL', 'New ChlRec: '); // + inttostr(id +1) + ' - ' +booltostr(rad, true));
      CHLrec.SortNum := -1;
      CHLrec.QSelect := -1; // no Quality-Rec selected
      // ----- DYNAMIC-DATA -----
      ChlRec.Qualy := TList.Create;
      CHLrec.EPG := TList.Create;
    end;
// else
// Log('UPDCHL', '********** CHL AVAILABLE: ' + booltostr(ChlRec.Is_Radio, true));
    // --- Set values new:
    ChlRec.Sharing := sha;
    ChlRec.Is_Radio := rad;
    StrLCopy(CHLrec.Title, PAnsiChar(tit), High(ChLrec.Title) - 1);
    StrLCopy(CHLrec.CID, PAnsiChar(cid), High(CHLrec.CID) - 1);
    ChlRec.Num := StrToInt(num);
    ChlRec.Recording := rec;
    // --- check CHANNEL-QUALITIES:
    // Section "qualities" will / must be present
    // we should have min. 1 (SD) , mostly 2 (HD+SD), more ?
    // TRICKY: first read "recommendations" for max. loop-position !
    posrem:= PosEx('"recommendations"', Data, posnext); // REMAIN "JUMP"
    numQRec := -1;
    // --- Clear QRecs if available:
    for i := 1 to ChlRec.Qualy.Count do
      Dispose(PChlQualyRec(ChlRec.Qualy[i - 1]));
    ChlRec.Qualy.Clear;
    // --- Read QRecs new
    s := GetStr(posnext, Data, '"stream_types": [', '],'); // get first qualy-data
    while (PosNext > 0) AND (PosRem > PosNext) do
    begin
      inc(numQrec);
      New(QRec); // 10)
      ChlRec.Qualy.Add(QRec);
      FillChar(QRec^, sizeof(TChlQualyRec), 0);
      // title - UNUSED HERE
      QRec.stream_types := GetSTreamTypes(s);
      QRec.level := 0; // default undefined
      s := GetStr(posnext, Data, '"level": "', '",');
      if (s = 'hd') then QRec.level := 2;
      if (s = 'sd') then QRec.level := 1;
      s := GetStr(posnext, Data, '"logo_token": "', '",');
      StrLCopy(QRec.logo_token , PAnsiChar(s), High(QRec.logo_token) - 1);
      s := GetStr(posnext, Data, '"availability": "', '"');
      QRec.available := (s = 'available');
      inc(PosNext, 5); // jump over last bracketsm komma & spaces !
//LOG('UPDCHL', '--- Q' + inttostr(numQRec) + ' - avail: ' + booltostr(QRec.available, true) +
// ' | level: ' + inttostr(QRec.level));
      // ----- Check if selectable:
      if (ChlRec.QSelect < 0) then
        if QRec.available then ChlRec.QSelect := ChlRec.Qualy.Count - 1;
      s := GetStr(posnext, Data, '"stream_types": [', '],'); // get next qualy-data
    end;
//LOG('UPDCHL', '--- selected: ' + inttostr(ChlRec.QSelect));
    PosNext := PosRem; // !!! ... because PosNext is in range of next channel !
    // Ignore: "recommendations" // 11)
    // Here: ... EPG-Now 7)
    // Ignore: "id": "ard", // 13)
    // Ignore: "aliases": ["daserste"] // 14)
    // IGNORE: FAV-block
    PosNext := PosEx('"display_alias"', Data, PosNext); // // get begin of next channel
  end;
Wie man sehen kann ist das sehr aufwendig und es ist nicht immer garantiert das diese art des Parsen zum gewünschten erfolg führt.
Meine frage daher wie kann ich das mit mORMot Json Parser umsetzen?
Sollte das funktionieren sollen mir die 280 KB egal sein.

Kenne das Framework nicht und ellenlange Englische Seiten zu lesen ist nicht mein Ding.

EDIT:
Dann kann ich
ShowMessage(docPrograms.S['g'].ToCSV);
In D2010 nicht übergeben so wie man im Shot sehen kann. (Ist nur ein String nicht gesplittet)
Zitat:
[DCC Error] Unit1.pas(125): E2018 Record, object or class type required

Geändert von venice2 (16. Dez 2020 um 16:27 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz