@@ -18,6 +18,7 @@ TJSONValueHelper = class helper for TJSONValue
1818 function GetPathValue (const Path: string): TJSONValue;
1919 function GetPathString (const Path: string; const Default: string = ' ' ): string;
2020 function GetPathInteger (const Path: string; const Default: Integer = 0 ): Integer;
21+ function GetPathInt64 (const Path: string; const Default: Int64 = 0 ): Int64;
2122 function GetPathBoolean (const Path: string; const Default: Boolean = False): Boolean;
2223 function GetPathDouble (const Path: string; const Default: Double = 0.0 ): Double;
2324 function GetPathObjectText (const Path: string; const Default: string = ' ' ): string;
@@ -71,6 +72,7 @@ TJsonRootHolder = class(TInterfacedObject, IJsonRootHolder)
7172
7273 function AsString (const Path: string; const Default: string = ' ' ): string;
7374 function AsInteger (const Path: string; const Default: Integer = 0 ): Integer;
75+ function AsInt64 (const Path: string; const Default: Int64 = 0 ): Int64;
7476 function AsBoolean (const Path: string; const Default: Boolean = False): Boolean;
7577 function AsDouble (const Path: string; const Default: Double = 0.0 ): Double;
7678
@@ -266,16 +268,27 @@ function TJSONValueHelper.RemovePath(const Path: string): Boolean;
266268
267269function TJSONValueHelper.GetPathString (const Path: string; const Default: string): string;
268270begin
271+ Result := Default;
272+
269273 var JSONValue := GetPathValue(Path);
270274 if JSONValue = nil then
271- Exit(Default);
275+ Exit;
276+
277+ if JSONValue is TJSONNull then
278+ Exit;
272279
273280 if JSONValue is TJSONString then
274281 Exit(TJSONString(JSONValue).Value );
275282
276283 if JSONValue is TJSONNumber then
277284 Exit(TJSONNumber(JSONValue).ToString);
278285
286+ if JSONValue is TJSONTrue then
287+ Exit(' true' );
288+
289+ if JSONValue is TJSONFalse then
290+ Exit(' false' );
291+
279292 Result := JSONValue.Value ;
280293 if Result.IsEmpty then
281294 Result := JSONValue.ToString;
@@ -290,6 +303,15 @@ function TJSONValueHelper.GetPathInteger(const Path: string; const Default: Inte
290303 Result := Default;
291304end ;
292305
306+ function TJSONValueHelper.GetPathInt64 (const Path: string; const Default: Int64): Int64;
307+ begin
308+ var S := GetPathString(Path, ' ' );
309+ if not S.IsEmpty and TryStrToInt64(S, Result) then
310+ Exit;
311+
312+ Result := Default;
313+ end ;
314+
293315function TJSONValueHelper.GetPathBoolean (const Path: string; const Default: Boolean): Boolean;
294316begin
295317 var S := GetPathString(Path, ' ' );
@@ -512,6 +534,15 @@ function TJsonReader.AsInteger(const Path: string; const Default: Integer): Inte
512534 Result := R.GetPathInteger(Path, Default);
513535end ;
514536
537+ function TJsonReader.AsInt64 (const Path: string; const Default: Int64): Int64;
538+ begin
539+ var R := Root;
540+ if R = nil then
541+ Exit(Default);
542+
543+ Result := R.GetPathInt64(Path, Default);
544+ end ;
545+
515546function TJsonReader.AsBoolean (const Path: string; const Default: Boolean): Boolean;
516547begin
517548 var R := Root;
@@ -562,10 +593,14 @@ function TJsonReader.ArrayFieldStrings(const ArrayPath,
562593 if (Item <> nil ) and (Item is TJSONObject) then
563594 begin
564595 var Field := TJSONObject(Item).GetValue(FieldName);
565- if (Field <> nil ) then
596+ if (Field <> nil ) and not (Field is TJSONNull) then
566597 begin
567598 if Field is TJSONString then
568599 Values.Add(TJSONString(Field).Value )
600+ else if Field is TJSONTrue then
601+ Values.Add(' true' )
602+ else if Field is TJSONFalse then
603+ Values.Add(' false' )
569604 else
570605 Values.Add(Field.Value );
571606 end ;
@@ -607,6 +642,9 @@ function TJsonReader.ExtractSubJson(const Path, Default: string): string;
607642 if V = nil then
608643 Exit;
609644
645+ if V is TJSONNull then
646+ Exit;
647+
610648 if (V is TJSONObject) or (V is TJSONArray) then
611649 Exit(V.ToJSON);
612650
@@ -616,6 +654,12 @@ function TJsonReader.ExtractSubJson(const Path, Default: string): string;
616654 if V is TJSONNumber then
617655 Exit(TJSONNumber(V).ToString);
618656
657+ if V is TJSONTrue then
658+ Exit(' true' );
659+
660+ if V is TJSONFalse then
661+ Exit(' false' );
662+
619663 Result := V.Value ;
620664 if Result.IsEmpty then
621665 Result := V.ToString;
0 commit comments