Permalink
Browse files

jsonDoc AsString property

  • Loading branch information...
stijnsanders committed Jan 17, 2019
1 parent e22e69d commit fb01e0865fa888c7441234726dc4a90b0c802582
Showing with 34 additions and 18 deletions.
  1. +5 −0 CHANGELOG.txt
  2. +18 −9 jsonDoc.pas
  3. +9 −8 jsonV.dof
  4. BIN jsonV.res
  5. +2 −1 jsonV1.pas
@@ -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

@@ -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;
@@ -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
@@ -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
@@ -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;

{
@@ -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;
@@ -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;

@@ -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;
@@ -1446,7 +1456,6 @@ function TJSONDocument.Parse(const JSONData: WideString): IJSONDocument;
LeaveCriticalSection(FLock);
end;
{$ENDIF}
Result:=Self;
end;

function JSONEncodeStr(const xx:WideString):WideString;
@@ -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]
@@ -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
@@ -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=
@@ -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;
BIN +0 Bytes (100%) jsonV.res
Binary file not shown.
@@ -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;

0 comments on commit fb01e08

Please sign in to comment.