Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompose: Add TJsonValueHelper (deprcate TJSONObjectHelper) #63

Open
bogdanpolak opened this issue Feb 4, 2023 · 0 comments
Open

Decompose: Add TJsonValueHelper (deprcate TJSONObjectHelper) #63

bogdanpolak opened this issue Feb 4, 2023 · 0 comments

Comments

@bogdanpolak
Copy link
Owner

bogdanpolak commented Feb 4, 2023

TJsonField = record
  fHasField: boolean;
  fPair: TJSONPair;
  constructor Create(const aField: string; const aValue: Variant);
  function HasDate: boolean;
  function AsString: strong;
  function AsDate: TDateTime;
  function AsInteger: integer;
  function AsBoolean: boolean;
  procedure SetValue(const aText: string); overloaded;
  procedure SetValue(const aDate: TDateTime);
  procedure SetValue(const aValue: integer);
  procedure SetValue(const aValue: boolean);
end;

function CreateJsonObject(aObjectData: TArray<TJsonField>): TJSONObject; 
// function TDataSetHelper.AsJson: TJSONArray;

TJsonValueHelper = class helper for TJSONValue
  function IsJsonArray: boolean;
  function IsJsonObject: boolean;
  function HasField(const aKey: string): boolean;   // expects JSONArray
  function GetField(const aKey: string): TJsonField;   // expects JSONArray
  function TryGetField(const aKey: string; out aJsonField: TJsonField): boolean;
  // --
  procedure AddField(const aKey: string; const aValue: Variant);
  procedure AddObject(aObjectData: TArray<TJsonField>);  // expects JSONArray
  // --
  // LoadFromFile, LoadFromStream, SaveToFile, SaveToStream
  // FromDBField, WriteToDBField - expects not TJSONObject and not TJSONArray 
  // FromDataRow, WriteToDataRow - expects TJSONObject
  // CreateClientDataSet - expects TJSONArray
end;

Sample JSONs (review):

https://stackoverflow.com/questions/24815625/parsing-valid-json-with-tjsonobject-using-embarcadero-code-example-fails-with-ex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant