AGB  ·  Datenschutz  ·  Impressum  







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

JSON - lesen eines JSON Elements

Ein Thema von wschrabi · begonnen am 17. Aug 2019 · letzter Beitrag vom 17. Aug 2019
 
samso

Registriert seit: 29. Mär 2009
439 Beiträge
 
#3

AW: JSON - lesen eines JSON Elements

  Alt 17. Aug 2019, 20:00
Code:
[
  {
    "total": "9",
    "page": "9",
    "records": "99",
    "rows": [
      {
        "id": "62316",
        "titleId": "47243",
        "subject": [
          "000607",
          "000607_",
          "001727"
        ],
        "keyFeatures": [
          "AI",
          "URL"
        ]
      },
      {
        "id": "66",
        "titleId": "47243",
        "subject": [
          "000607",
          "000607_",
          "001727"
        ],
        "keyFeatures": [
          "KK"
        ]
      }
    ],
    "suggestion": "90"
  }
]
Mir ist Dein Quelltext zu anstrengend. Ich halte mich da eher an das Beispiel aus Stackoverflow.
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  DataBase: String;
  JsonArray: TJSONArray;
  ArrayElement: TJSonValue;
  RowValue: TJSonValue;
  RowItem: TJSonValue;
  keyFeatures: TJSonValue;
  FeatureItem: TJSonValue;
  FeatureList: TStringlist;
  Id: Integer;
  Index: Integer;
begin
  Memo1.Clear;
  DataBase :=
    '[{"total":"9","page":"9","records":"99","rows":[{"id":"62316","titleId":"47243","subject":'
    + '["000607","000607_","001727"],"keyFeatures":["AI","URL"]},{"id":"66","titleId":"47243","subject":'
    + '["000607","000607_","001727"],"keyFeatures":["KK"]}],"suggestion":"90"}]';

  JsonArray := TJSonObject.ParseJSONValue(DataBase) as TJSONArray;
  try
    Index := 1;
    for ArrayElement in JsonArray do
    begin
      RowValue := (ArrayElement as TJSonObject).GetValue('rows');
      if RowValue is TJSONArray
      then
      begin
        for RowItem in TJSONArray(RowValue) do
        begin
          RowItem.TryGetValue('id', Id);
          keyFeatures := (RowItem as TJSonObject).GetValue('keyFeatures');
          if keyFeatures is TJSONArray
          then
          begin
            FeatureList := TStringlist.Create;
            try
              for FeatureItem in TJSONArray(keyFeatures) do
                FeatureList.Add(FeatureItem.Value);
              Memo1.Lines.Add(Format('%d: %d KeyFeatures: %s', [Index, Id, FeatureList.CommaText]));
            finally
              FeatureList.Free;
            end;
          end;
          inc(Index);
        end;
      end;
    end;
  finally
    JsonArray.Free;
  end;
end;

Geändert von samso (17. Aug 2019 um 20:33 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 07:13 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