Einzelnen Beitrag anzeigen

Benutzerbild von NoGAD
NoGAD

Registriert seit: 31. Jan 2006
Ort: Weimar
344 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: XML-Schema auswerten (Link)

  Alt 23. Feb 2020, 15:32
Hallo nochmal,

bisher klappt alles ganz gut, indem ich den json String parse.

Leider habe ich noch ein Problem mit der ersten Variable in der Struktur: items.

Das ist ein Array, von welchem ich die Anzahl der Elemente nicht auslesen kann.

Also so etwas wie

Code:
  var
    JSonObject : TJSONObject;
    JSonValue : TJSonValue;
    Items : TJSonArray;

    TotalItems : Integer;

    Dummy_String : String;
  begin
    Dummy_String := IdHTTP1.Get( Dummy_String );

    JSonObject := TJSONObject.ParseJSONValue( Dummy_String ) as TJSONObject;
    JSonValue := TJSONObject.ParseJSONValue( Dummy_String );

    TotalItems := JSonValue.GetValue< Integer >( 'totalItems' );

    if TotalItems = 0 then
    begin
      ShowMessage( Message_ISBN_NoItems );
      Exit;
    end;

    Items := JSonObject.GetValue< TJSonArray >( 'Items' );
Wie bekomme ich die anzahl der Elemente von Items?

In folgendem Beispiel sind es 10: https://www.googleapis.com/books/v1/...=9783499244551

LG Mathias





Edit:

Habe es gefunden, war eine Blockade

Code:
    if JSonObject.TryGetValue( 'items', Items ) then
      Items := JSonValue.GetValue< TJSONArray >( 'items' );

    { : Mehrere Items wurden gefunden, in eine Auswahlliste : }
    if Items.Count > 1 then
Mathias

Geändert von NoGAD (23. Feb 2020 um 16:01 Uhr) Grund: Selbst gefunden
  Mit Zitat antworten Zitat