From 532bf2523350e0ddf292b14b34dfecf30f3becb5 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 27 Feb 2016 09:13:31 +0000 Subject: [PATCH] * Add possibility to specify JSON options git-svn-id: trunk@33124 - --- packages/fcl-json/src/jsonconf.pp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/fcl-json/src/jsonconf.pp b/packages/fcl-json/src/jsonconf.pp index 0d54755296..7c3f95143d 100644 --- a/packages/fcl-json/src/jsonconf.pp +++ b/packages/fcl-json/src/jsonconf.pp @@ -30,6 +30,8 @@ interface uses SysUtils, Classes, fpjson, jsonscanner, jsonparser; +Const + DefaultJSONOptions = [joUTF8,joComments]; type EJSONConfigError = class(Exception); @@ -57,9 +59,11 @@ type FFormatIndentSize: Integer; FFormatoptions: TFormatOptions; FFormatted: Boolean; + FJSONOptions: TJSONOptions; FKey: TJSONObject; procedure DoSetFilename(const AFilename: String; ForceReload: Boolean); procedure SetFilename(const AFilename: String); + procedure SetJSONOptions(AValue: TJSONOptions); Function StripSlash(Const P : UnicodeString) : UnicodeString; protected FJSON: TJSONObject; @@ -109,6 +113,7 @@ type Property Formatted : Boolean Read FFormatted Write FFormatted; Property FormatOptions : TFormatOptions Read FFormatoptions Write FFormatOptions Default DefaultFormat; Property FormatIndentsize : Integer Read FFormatIndentSize Write FFormatIndentSize Default DefaultIndentSize; + Property JSONOptions : TJSONOptions Read FJSONOptions Write SetJSONOptions Default DefaultJSONOptions; end; @@ -127,6 +132,7 @@ begin FKey:=FJSON; FFormatOptions:=DefaultFormat; FFormatIndentsize:=DefaultIndentSize; + FJSONOptions:=DefaultJSONOptions; end; destructor TJSONConfig.Destroy; @@ -687,7 +693,7 @@ begin begin F:=TFileStream.Create(AFileName,fmopenRead); try - P:=TJSONParser.Create(F,[joUTF8,joComments]); + P:=TJSONParser.Create(F,FJSONOptions); try J:=P.Parse; If (J is TJSONObject) then @@ -712,6 +718,16 @@ begin DoSetFilename(AFilename, False); end; +procedure TJSONConfig.SetJSONOptions(AValue: TJSONOptions); +begin + if FJSONOptions=AValue then Exit; + FJSONOptions:=AValue; + if csLoading in ComponentState then + exit; + if (FFileName<>'') then + Reload; +end; + function TJSONConfig.StripSlash(const P: UnicodeString): UnicodeString; Var