AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Array Properties

Ein Thema von Rabenrecht · begonnen am 25. Okt 2022 · letzter Beitrag vom 28. Okt 2022
Antwort Antwort
mytbo

Registriert seit: 8. Jan 2007
480 Beiträge
 
#1

AW: Array Properties

  Alt 25. Okt 2022, 17:56
Json Serialization ist der einzige Grund, warum ich hier überhaupt mit Arrays rumhühnere, anstatt einfach (Object)Listen zu nutzen.
Wenn es auch mORMot sein darf, dann mit ObjectToJson/ObjectLoadJson so:
Delphi-Quellcode:
uses
  mormot.core.base,
  mormot.core.json,
  mormot.core.text,
  mormot.core.rtti,
  mormot.core.unicode;
  
type
  TItem = class(TObject)
  private
    FIntValue: Integer;
    FStrValue: RawUtf8;
  public
    constructor Create(pmIntValue: Integer; const pmcStrValue: RawUtf8);
  published
    property IntValue: Integer
      read FIntValue;
    property StrValue: RawUtf8
      read FStrValue;
  end;

constructor TItem.Create(pmIntValue: Integer; const pmcStrValue: RawUtf8);
begin
  inherited Create;
  FIntValue := pmIntValue;
  FStrValue := pmcStrValue;
end;

var
  json: RawJson;
  list: TObjectList;
begin
  list := TObjectList.Create(True);
  try
    for var i: Integer := 0 to 4 do
      list.Add(TItem.Create(i, StringToUtf8(i.ToString)));

    json := ObjectToJson(list, [woHumanReadable, woObjectListWontStoreClassName]);
    ShowMessage(Utf8ToString(json));

    list.Clear;
    ObjectLoadJson(list, json, TItem);
    ShowMessage(Format('Count: %d - Item(3): %d, %s',[list.Count, TItem(list[3]).IntValue, Utf8ToString(TItem(list[3]).StrValue)]));
  finally
    list.Free;
  end;
Die JSON Serialisierung gehört zur mORMot DNA.

Bis bald...
Thomas
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 13:16 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