Skip to content

Commit

Permalink
jsonDoc AsString property
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnsanders committed Jan 17, 2019
1 parent e22e69d commit fb01e08
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v1.2.0
### ATTENTION!!! breaking change: ###
- Parse is now a procedure instead of a function, to enable it as the writer for the AsString property while keeping the same number of virtual methods in the IJSONDocument interface.
- conditional define JSONDOC_P2 to combine JSONDOC_JSON_LOOSE and JSONDOC_JSON_PASCAL_STRINGS

v1.1.8
- revised parsing arrays of combined numerical types

Expand Down
27 changes: 18 additions & 9 deletions jsonDoc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
jsonDoc.pas
Copyright 2015-2018 Stijn Sanders
Copyright 2015-2019 Stijn Sanders
Made available under terms described in file "LICENSE"
https://github.com/stijnsanders/jsonDoc
v1.1.9
v1.2.0
}
unit jsonDoc;
Expand All @@ -29,6 +29,9 @@
JSONDOC_JSON_PASCAL_STRINGS
to allow pascal-style strings
JSONDOC_P2
to combine JSONDOC_JSON_LOOSE and JSONDOC_JSON_PASCAL_STRINGS
JSONDOC_STOREINDENTING
to make ToString write indentation EOL's and tabs
Expand Down Expand Up @@ -66,8 +69,8 @@ interface
IJSONDocument interface
the base JSON document interface that provides access to a set of
key-value pairs.
use ToString and Parse to convert JSON to and from string values.
use ToVarArray to access the key-value pairs as a [x,2] variant array.
use AsString and Parse to convert JSON to and from string values.
use AsVarArray to access the key-value pairs as a [x,2] variant array.
use Clear to re-use a JSON doc for parsing or building a new similar
document and keep the allocated memory for keys and values.
see also: JSON function
Expand All @@ -76,13 +79,14 @@ interface
['{4A534F4E-0001-0001-C000-000000000001}']
function Get_Item(const Key: WideString): Variant; stdcall;
procedure Set_Item(const Key: WideString; const Value: Variant); stdcall;
function Parse(const JSONData: WideString): IJSONDocument; stdcall;
procedure Parse(const JSONData: WideString); stdcall;
function ToString: WideString; stdcall;
function ToVarArray: Variant; stdcall;
procedure Clear; stdcall;
procedure Delete(const Key: WideString); stdcall;
property Item[const Key: WideString]: Variant
read Get_Item write Set_Item; default;
procedure Delete(const Key: WideString); stdcall;
property AsString: WideString read ToString write Parse;
end;

{
Expand Down Expand Up @@ -276,7 +280,7 @@ TJSONDocument = class(TJSONImplBaseObj, IJSONDocument, IJSONEnumerable,
public
procedure AfterConstruction; override;
destructor Destroy; override;
function Parse(const JSONData: WideString): IJSONDocument; stdcall;
procedure Parse(const JSONData: WideString); stdcall;
function JSONToString: WideString; stdcall;
function IJSONDocument.ToString=JSONToString;
function ToVarArray: Variant; stdcall;
Expand All @@ -285,6 +289,7 @@ TJSONDocument = class(TJSONImplBaseObj, IJSONDocument, IJSONEnumerable,
procedure Delete(const Key: WideString); stdcall;
property Item[const Key: WideString]: Variant
read Get_Item write Set_Item; default;
property AsString: WideString read JSONToString write Parse;
property UseIJSONArray:boolean read FUseIJSONArray write FUseIJSONArray;
end;

Expand Down Expand Up @@ -652,7 +657,12 @@ procedure TJSONDocument.Set_Item(const Key: WideString; const Value: Variant);
{$ENDIF}
end;

function TJSONDocument.Parse(const JSONData: WideString): IJSONDocument;
{$IFDEF JSONDOC_P2}
{$DEFINE JSONDOC_JSON_LOOSE}
{$DEFINE JSONDOC_JSON_PASCAL_STRINGS}
{$ENDIF}

procedure TJSONDocument.Parse(const JSONData: WideString);
var
i,l:integer;
function SkipWhiteSpace:WideChar;
Expand Down Expand Up @@ -1446,7 +1456,6 @@ function TJSONDocument.Parse(const JSONData: WideString): IJSONDocument;
LeaveCriticalSection(FLock);
end;
{$ENDIF}
Result:=Self;
end;

function JSONEncodeStr(const xx:WideString):WideString;
Expand Down
17 changes: 9 additions & 8 deletions jsonV.dof
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ PackageDLLOutputDir=
PackageDCPOutputDir=
SearchPath=
Packages=vcl;rtl;vclie;xmlrtl;inet;inetdbbde;inetdbxpress;vclx;dbrtl;soaprtl;dsnap;VclSmp;dbexpress;vcldb;dbxcds;adortl;ibxpress;vclactnband;bdertl;vclshlctrls
Conditionals=JSONDOC_JSON_PASCAL_STRINGS;JSONDOC_JSON_LOOSE
Conditionals=JSONDOC_P2
DebugSourceDirs=
UsePackages=0
[Parameters]
Expand All @@ -109,9 +109,9 @@ DebugCWD=
IncludeVerInfo=1
AutoIncBuild=0
MajorVer=1
MinorVer=1
Release=8
Build=567
MinorVer=2
Release=0
Build=570
Debug=0
PreRelease=0
Special=0
Expand All @@ -122,7 +122,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=jsonV
FileVersion=1.1.8.567
FileVersion=1.2.0.570
InternalName=
LegalCopyright=
LegalTrademarks=
Expand All @@ -133,9 +133,10 @@ Comments=http://yoy.be/jsonV.html
[Excluded Packages]
c:\delphi7\Projects\Bpl\VirtualTreesD.bpl=Virtual Treeview design time package
[HistoryLists\hlConditionals]
Count=2
Item0=JSONDOC_JSON_PASCAL_STRINGS;JSONDOC_JSON_LOOSE
Item1=JSONDOC_JSON_STRICT
Count=3
Item0=JSONDOC_P2
Item1=JSONDOC_JSON_PASCAL_STRINGS;JSONDOC_JSON_LOOSE
Item2=JSONDOC_JSON_STRICT
[HistoryLists\hlUnitAliases]
Count=1
Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
Expand Down
Binary file modified jsonV.res
Binary file not shown.
3 changes: 2 additions & 1 deletion jsonV1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function TfrmJsonViewer.LoadJSON(const FilePath: string): IJSONDocument;
m.Free;
end;
if (w<>'') and (w[1]='[') then w:='{"":'+w+'}';
Result:=JSON.Parse(w);
Result:=JSON;
Result.Parse(w);
end;

procedure TfrmJsonViewer.TreeView1Expanding(Sender: TObject;
Expand Down

0 comments on commit fb01e08

Please sign in to comment.