Răsfoiți Sursa

* Patch from Inoussa OUEDRAOGO to support int64 numbers

git-svn-id: trunk@13358 -
michael 16 ani în urmă
părinte
comite
04f1614e0b

+ 231 - 2
packages/fcl-json/src/fpjson.pp

@@ -39,10 +39,12 @@ type
     function GetAsBoolean: Boolean; virtual; abstract;
     function GetAsBoolean: Boolean; virtual; abstract;
     function GetAsFloat: TJSONFloat; virtual; abstract;
     function GetAsFloat: TJSONFloat; virtual; abstract;
     function GetAsInteger: Integer; virtual; abstract;
     function GetAsInteger: Integer; virtual; abstract;
+    function GetAsInt64: Int64; virtual; abstract;
     function GetIsNull: Boolean; virtual;
     function GetIsNull: Boolean; virtual;
     procedure SetAsBoolean(const AValue: Boolean); virtual; abstract;
     procedure SetAsBoolean(const AValue: Boolean); virtual; abstract;
     procedure SetAsFloat(const AValue: TJSONFloat); virtual; abstract;
     procedure SetAsFloat(const AValue: TJSONFloat); virtual; abstract;
     procedure SetAsInteger(const AValue: Integer); virtual; abstract;
     procedure SetAsInteger(const AValue: Integer); virtual; abstract;
+    procedure SetAsInt64(const AValue: Int64); virtual; abstract;
     function GetAsJSON: TJSONStringType; virtual; abstract;
     function GetAsJSON: TJSONStringType; virtual; abstract;
     function GetAsString: TJSONStringType; virtual; abstract;
     function GetAsString: TJSONStringType; virtual; abstract;
     procedure SetAsString(const AValue: TJSONStringType); virtual; abstract;
     procedure SetAsString(const AValue: TJSONStringType); virtual; abstract;
@@ -61,13 +63,14 @@ type
     Property AsString : TJSONStringType Read GetAsString Write SetAsString;
     Property AsString : TJSONStringType Read GetAsString Write SetAsString;
     Property AsFloat : TJSONFloat Read GetAsFloat Write SetAsFloat;
     Property AsFloat : TJSONFloat Read GetAsFloat Write SetAsFloat;
     Property AsInteger : Integer Read GetAsInteger Write SetAsInteger;
     Property AsInteger : Integer Read GetAsInteger Write SetAsInteger;
+    Property AsInt64 : Int64 Read GetAsInt64 Write SetAsInt64;
     Property AsBoolean : Boolean Read GetAsBoolean Write SetAsBoolean;
     Property AsBoolean : Boolean Read GetAsBoolean Write SetAsBoolean;
     Property IsNull : Boolean Read GetIsNull;
     Property IsNull : Boolean Read GetIsNull;
     Property AsJSON : TJSONStringType Read GetAsJSON;
     Property AsJSON : TJSONStringType Read GetAsJSON;
   end;
   end;
 
 
   TJSONDataClass = Class of TJSONData;
   TJSONDataClass = Class of TJSONData;
-  TJSONNumberType = (ntFloat,ntInteger);
+  TJSONNumberType = (ntFloat,ntInteger,ntInt64);
 
 
   TJSONNumber = class(TJSONData)
   TJSONNumber = class(TJSONData)
   protected
   protected
@@ -85,9 +88,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -108,9 +113,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -122,6 +129,31 @@ type
     Procedure Clear;  override;
     Procedure Clear;  override;
   end;
   end;
 
 
+  { TJSONInt64Number }
+
+  TJSONInt64Number = class(TJSONNumber)
+  Private
+    FValue : Int64;
+  protected
+    function GetAsBoolean: Boolean; override;
+    function GetAsFloat: TJSONFloat; override;
+    function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
+    procedure SetAsBoolean(const AValue: Boolean); override;
+    procedure SetAsFloat(const AValue: TJSONFloat); override;
+    procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
+    function GetAsJSON: TJSONStringType; override;
+    function GetAsString: TJSONStringType; override;
+    procedure SetAsString(const AValue: TJSONStringType); override;
+    function GetValue: variant; override;
+    procedure SetValue(const AValue: variant); override;
+  public
+    Constructor Create(AValue : Int64); reintroduce;
+    class function NumberType : TJSONNumberType; override;
+    Procedure Clear;  override;
+  end;
+
   { TJSONString }
   { TJSONString }
 
 
   TJSONString = class(TJSONData)
   TJSONString = class(TJSONData)
@@ -133,9 +165,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -156,9 +190,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -176,10 +212,12 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     function GetIsNull: Boolean; override;
     function GetIsNull: Boolean; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -202,6 +240,7 @@ type
     function GetBooleans(Index : Integer): Boolean;
     function GetBooleans(Index : Integer): Boolean;
     function GetFloats(Index : Integer): TJSONFloat;
     function GetFloats(Index : Integer): TJSONFloat;
     function GetIntegers(Index : Integer): Integer;
     function GetIntegers(Index : Integer): Integer;
+    function GetInt64s(Index : Integer): Int64;
     function GetNulls(Index : Integer): Boolean;
     function GetNulls(Index : Integer): Boolean;
     function GetObjects(Index : Integer): TJSONObject;
     function GetObjects(Index : Integer): TJSONObject;
     function GetStrings(Index : Integer): TJSONStringType;
     function GetStrings(Index : Integer): TJSONStringType;
@@ -210,6 +249,7 @@ type
     procedure SetBooleans(Index : Integer; const AValue: Boolean);
     procedure SetBooleans(Index : Integer; const AValue: Boolean);
     procedure SetFloats(Index : Integer; const AValue: TJSONFloat);
     procedure SetFloats(Index : Integer; const AValue: TJSONFloat);
     procedure SetIntegers(Index : Integer; const AValue: Integer);
     procedure SetIntegers(Index : Integer; const AValue: Integer);
+    procedure SetInt64s(Index : Integer; const AValue: Int64);
     procedure SetObjects(Index : Integer; const AValue: TJSONObject);
     procedure SetObjects(Index : Integer; const AValue: TJSONObject);
     procedure SetStrings(Index : Integer; const AValue: TJSONStringType);
     procedure SetStrings(Index : Integer; const AValue: TJSONStringType);
   protected
   protected
@@ -217,9 +257,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -240,6 +282,7 @@ type
     Procedure Clear;  override;
     Procedure Clear;  override;
     function Add(Item : TJSONData): Integer;
     function Add(Item : TJSONData): Integer;
     function Add(I : Integer): Integer;
     function Add(I : Integer): Integer;
+    function Add(I : Int64): Int64;
     function Add(S : String): Integer;
     function Add(S : String): Integer;
     function Add: Integer;
     function Add: Integer;
     function Add(F : TJSONFloat): Integer;
     function Add(F : TJSONFloat): Integer;
@@ -253,6 +296,7 @@ type
     Property Types[Index : Integer] : TJSONType Read GetTypes;
     Property Types[Index : Integer] : TJSONType Read GetTypes;
     Property Nulls[Index : Integer] : Boolean Read GetNulls;
     Property Nulls[Index : Integer] : Boolean Read GetNulls;
     Property Integers[Index : Integer] : Integer Read GetIntegers Write SetIntegers;
     Property Integers[Index : Integer] : Integer Read GetIntegers Write SetIntegers;
+    Property Int64s[Index : Integer] : Int64 Read GetInt64s Write SetInt64s;
     Property Strings[Index : Integer] : TJSONStringType Read GetStrings Write SetStrings;
     Property Strings[Index : Integer] : TJSONStringType Read GetStrings Write SetStrings;
     Property Floats[Index : Integer] : TJSONFloat Read GetFloats Write SetFloats;
     Property Floats[Index : Integer] : TJSONFloat Read GetFloats Write SetFloats;
     Property Booleans[Index : Integer] : Boolean Read GetBooleans Write SetBooleans;
     Property Booleans[Index : Integer] : Boolean Read GetBooleans Write SetBooleans;
@@ -272,6 +316,7 @@ type
     function GetElements(AName: string): TJSONData;
     function GetElements(AName: string): TJSONData;
     function GetFloats(AName : String): TJSONFloat;
     function GetFloats(AName : String): TJSONFloat;
     function GetIntegers(AName : String): Integer;
     function GetIntegers(AName : String): Integer;
+    function GetInt64s(AName : String): Int64;
     function GetIsNull(AName : String): Boolean; reintroduce;
     function GetIsNull(AName : String): Boolean; reintroduce;
     function GetNameOf(Index : Integer): TJSONStringType;
     function GetNameOf(Index : Integer): TJSONStringType;
     function GetObjects(AName : String): TJSONObject;
     function GetObjects(AName : String): TJSONObject;
@@ -282,6 +327,7 @@ type
     procedure SetElements(AName: string; const AValue: TJSONData);
     procedure SetElements(AName: string; const AValue: TJSONData);
     procedure SetFloats(AName : String; const AValue: TJSONFloat);
     procedure SetFloats(AName : String; const AValue: TJSONFloat);
     procedure SetIntegers(AName : String; const AValue: Integer);
     procedure SetIntegers(AName : String; const AValue: Integer);
+    procedure SetInt64s(AName : String; const AValue: Int64);
     procedure SetIsNull(AName : String; const AValue: Boolean);
     procedure SetIsNull(AName : String; const AValue: Boolean);
     procedure SetObjects(AName : String; const AValue: TJSONObject);
     procedure SetObjects(AName : String; const AValue: TJSONObject);
     procedure SetStrings(AName : String; const AValue: TJSONStringType);
     procedure SetStrings(AName : String; const AValue: TJSONStringType);
@@ -290,9 +336,11 @@ type
     function GetAsBoolean: Boolean; override;
     function GetAsBoolean: Boolean; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsFloat: TJSONFloat; override;
     function GetAsInteger: Integer; override;
     function GetAsInteger: Integer; override;
+    function GetAsInt64: Int64; override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsBoolean(const AValue: Boolean); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsFloat(const AValue: TJSONFloat); override;
     procedure SetAsInteger(const AValue: Integer); override;
     procedure SetAsInteger(const AValue: Integer); override;
+    procedure SetAsInt64(const AValue: Int64); override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsJSON: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     function GetAsString: TJSONStringType; override;
     procedure SetAsString(const AValue: TJSONStringType); override;
     procedure SetAsString(const AValue: TJSONStringType); override;
@@ -317,6 +365,7 @@ type
     function Add(const AName: TJSONStringType; AValue: TJSONFloat): Integer; overload;
     function Add(const AName: TJSONStringType; AValue: TJSONFloat): Integer; overload;
     function Add(const AName: TJSONStringType; AValue: TJSONStringType): Integer; overload;
     function Add(const AName: TJSONStringType; AValue: TJSONStringType): Integer; overload;
     function Add(const AName: TJSONStringType; Avalue: Integer): Integer; overload;
     function Add(const AName: TJSONStringType; Avalue: Integer): Integer; overload;
+    function Add(const AName: TJSONStringType; Avalue: Int64): Integer; overload;
     function Add(const AName: TJSONStringType): Integer; overload;
     function Add(const AName: TJSONStringType): Integer; overload;
     function Add(const AName: TJSONStringType; AValue : TJSONArray): Integer; overload;
     function Add(const AName: TJSONStringType; AValue : TJSONArray): Integer; overload;
     procedure Delete(Index : Integer);
     procedure Delete(Index : Integer);
@@ -330,6 +379,7 @@ type
     Property Nulls[AName : String] : Boolean Read GetIsNull Write SetIsNull;
     Property Nulls[AName : String] : Boolean Read GetIsNull Write SetIsNull;
     Property Floats[AName : String] : TJSONFloat Read GetFloats Write SetFloats;
     Property Floats[AName : String] : TJSONFloat Read GetFloats Write SetFloats;
     Property Integers[AName : String] : Integer Read GetIntegers Write SetIntegers;
     Property Integers[AName : String] : Integer Read GetIntegers Write SetIntegers;
+    Property Int64s[AName : String] : Int64 Read GetInt64s Write SetInt64s;
     Property Strings[AName : String] : TJSONStringType Read GetStrings Write SetStrings;
     Property Strings[AName : String] : TJSONStringType Read GetStrings Write SetStrings;
     Property Booleans[AName : String] : Boolean Read GetBooleans Write SetBooleans;
     Property Booleans[AName : String] : Boolean Read GetBooleans Write SetBooleans;
     Property Arrays[AName : String] : TJSONArray Read GetArrays Write SetArrays;
     Property Arrays[AName : String] : TJSONArray Read GetArrays Write SetArrays;
@@ -534,6 +584,11 @@ begin
   Result:=StrToInt(FValue);
   Result:=StrToInt(FValue);
 end;
 end;
 
 
+function TJSONstring.GetAsInt64: Int64;
+begin
+  Result:=StrToInt64(FValue);
+end;
+
 procedure TJSONstring.SetAsBoolean(const AValue: Boolean);
 procedure TJSONstring.SetAsBoolean(const AValue: Boolean);
 begin
 begin
   FValue:=BoolToStr(AValue);
   FValue:=BoolToStr(AValue);
@@ -549,6 +604,11 @@ begin
   FValue:=IntToStr(AValue);
   FValue:=IntToStr(AValue);
 end;
 end;
 
 
+procedure TJSONstring.SetAsInt64(const AValue: Int64);
+begin
+  FValue:=IntToStr(AValue);
+end;
+
 function TJSONstring.GetAsJSON: TJSONStringType;
 function TJSONstring.GetAsJSON: TJSONStringType;
 begin
 begin
   Result:='"'+StringToJSONString(FValue)+'"';
   Result:='"'+StringToJSONString(FValue)+'"';
@@ -608,6 +668,10 @@ begin
   Result:=Ord(FValue);
   Result:=Ord(FValue);
 end;
 end;
 
 
+function TJSONboolean.GetAsInt64: Int64;
+begin
+  Result:=Ord(FValue);
+end;
 
 
 procedure TJSONboolean.SetAsBoolean(const AValue: Boolean);
 procedure TJSONboolean.SetAsBoolean(const AValue: Boolean);
 begin
 begin
@@ -624,6 +688,11 @@ begin
   FValue:=(AValue<>0)
   FValue:=(AValue<>0)
 end;
 end;
 
 
+procedure TJSONboolean.SetAsInt64(const AValue: Int64);
+begin
+  FValue:=(AValue<>0)
+end;
+
 function TJSONboolean.GetAsJSON: TJSONStringType;
 function TJSONboolean.GetAsJSON: TJSONStringType;
 begin
 begin
   If FValue then
   If FValue then
@@ -673,6 +742,11 @@ begin
   ConvertError(True);
   ConvertError(True);
 end;
 end;
 
 
+function TJSONnull.GetAsInt64: Int64;
+begin
+  ConvertError(True);
+end;
+
 function TJSONnull.GetIsNull: Boolean;
 function TJSONnull.GetIsNull: Boolean;
 begin
 begin
   Result:=True;
   Result:=True;
@@ -693,6 +767,11 @@ begin
   ConvertError(False);
   ConvertError(False);
 end;
 end;
 
 
+procedure TJSONnull.SetAsInt64(const AValue: Int64);
+begin
+  ConvertError(False);
+end;
+
 function TJSONnull.GetAsJSON: TJSONStringType;
 function TJSONnull.GetAsJSON: TJSONStringType;
 begin
 begin
   Result:='Null';
   Result:='Null';
@@ -748,6 +827,11 @@ begin
   Result:=Round(FValue);
   Result:=Round(FValue);
 end;
 end;
 
 
+function TJSONFloatNumber.GetAsInt64: Int64;
+begin
+  Result:=Round(FValue);
+end;
+
 procedure TJSONFloatNumber.SetAsBoolean(const AValue: Boolean);
 procedure TJSONFloatNumber.SetAsBoolean(const AValue: Boolean);
 begin
 begin
   FValue:=Ord(AValue);
   FValue:=Ord(AValue);
@@ -763,6 +847,11 @@ begin
   FValue:=AValue;
   FValue:=AValue;
 end;
 end;
 
 
+procedure TJSONFloatNumber.SetAsInt64(const AValue: Int64);
+begin
+  FValue:=AValue;
+end;
+
 function TJSONFloatNumber.GetAsJSON: TJSONStringType;
 function TJSONFloatNumber.GetAsJSON: TJSONStringType;
 begin
 begin
   Result:=AsString;
   Result:=AsString;
@@ -826,6 +915,11 @@ begin
   Result:=FValue;
   Result:=FValue;
 end;
 end;
 
 
+function TJSONIntegerNumber.GetAsInt64: Int64;
+begin
+  Result:=FValue;
+end;
+
 procedure TJSONIntegerNumber.SetAsBoolean(const AValue: Boolean);
 procedure TJSONIntegerNumber.SetAsBoolean(const AValue: Boolean);
 begin
 begin
   FValue:=Ord(AValue);
   FValue:=Ord(AValue);
@@ -841,6 +935,11 @@ begin
   FValue:=AValue;
   FValue:=AValue;
 end;
 end;
 
 
+procedure TJSONIntegerNumber.SetAsInt64(const AValue: Int64);
+begin
+  FValue:=AValue;
+end;
+
 function TJSONIntegerNumber.GetAsJSON: TJSONStringType;
 function TJSONIntegerNumber.GetAsJSON: TJSONStringType;
 begin
 begin
   Result:=AsString;
   Result:=AsString;
@@ -881,6 +980,87 @@ begin
   FValue:=0;
   FValue:=0;
 end;
 end;
 
 
+{ TJSONInt64Number }
+
+function TJSONInt64Number.GetAsInt64: Int64;
+begin
+  Result := FValue;
+end;
+
+procedure TJSONInt64Number.SetAsInt64(const AValue: Int64);
+begin
+  FValue := AValue;
+end;
+
+function TJSONInt64Number.GetAsBoolean: Boolean;
+begin
+  Result:=FValue<>0;
+end;
+
+function TJSONInt64Number.GetAsFloat: TJSONFloat;
+begin
+  Result:= FValue;
+end;
+
+function TJSONInt64Number.GetAsInteger: Integer;
+begin
+  Result := FValue;
+end;
+
+procedure TJSONInt64Number.SetAsBoolean(const AValue: Boolean);
+begin
+  FValue:=Ord(AValue);
+end;
+
+procedure TJSONInt64Number.SetAsFloat(const AValue: TJSONFloat);
+begin
+  FValue:=Round(AValue);
+end;
+
+procedure TJSONInt64Number.SetAsInteger(const AValue: Integer);
+begin
+  FValue:=AValue;
+end;
+
+function TJSONInt64Number.GetAsJSON: TJSONStringType;
+begin
+  Result:=AsString;
+end;
+
+function TJSONInt64Number.GetAsString: TJSONStringType;
+begin
+  Result:=IntToStr(FValue)
+end;
+
+procedure TJSONInt64Number.SetAsString(const AValue: TJSONStringType);
+begin
+  FValue:=StrToInt64(AValue);
+end;
+
+function TJSONInt64Number.GetValue: variant;
+begin
+  Result:=FValue;
+end;
+
+procedure TJSONInt64Number.SetValue(const AValue: variant);
+begin
+  FValue:=AValue;
+end;
+
+constructor TJSONInt64Number.Create(AValue: Int64);
+begin
+  FValue := AValue;
+end;
+
+class function TJSONInt64Number.NumberType: TJSONNumberType;
+begin
+  Result:=ntInt64;
+end;
+
+procedure TJSONInt64Number.Clear;
+begin
+  FValue:=0;
+end;
 
 
 { TJSONArray }
 { TJSONArray }
 
 
@@ -904,6 +1084,11 @@ begin
   Result:=Items[Index].AsInteger;
   Result:=Items[Index].AsInteger;
 end;
 end;
 
 
+function TJSONArray.GetInt64s(Index : Integer): Int64;
+begin
+  Result:=Items[Index].AsInt64;
+end;
+
 function TJSONArray.GetNulls(Index : Integer): Boolean;
 function TJSONArray.GetNulls(Index : Integer): Boolean;
 begin
 begin
   Result:=Items[Index].IsNull;
   Result:=Items[Index].IsNull;
@@ -945,6 +1130,11 @@ begin
   Items[Index]:=TJSONIntegerNumber.Create(AValue);
   Items[Index]:=TJSONIntegerNumber.Create(AValue);
 end;
 end;
 
 
+procedure TJSONArray.SetInt64s(Index : Integer; const AValue: Int64);
+begin
+  Items[Index]:=TJSONInt64Number.Create(AValue);
+end;
+
 procedure TJSONArray.SetObjects(Index : Integer; const AValue: TJSONObject);
 procedure TJSONArray.SetObjects(Index : Integer; const AValue: TJSONObject);
 begin
 begin
   Items[Index]:=AValue;
   Items[Index]:=AValue;
@@ -979,6 +1169,11 @@ begin
   ConvertError(True);
   ConvertError(True);
 end;
 end;
 
 
+function TJSONArray.GetAsInt64: Int64;
+begin
+  ConvertError(True);
+end;
+
 procedure TJSONArray.SetAsBoolean(const AValue: Boolean);
 procedure TJSONArray.SetAsBoolean(const AValue: Boolean);
 begin
 begin
   ConvertError(False);
   ConvertError(False);
@@ -993,6 +1188,10 @@ procedure TJSONArray.SetAsInteger(const AValue: Integer);
 begin
 begin
   ConvertError(False);
   ConvertError(False);
 end;
 end;
+procedure TJSONArray.SetAsInt64(const AValue: Int64);
+begin
+  ConvertError(False);
+end;
 {$warnings on}
 {$warnings on}
 
 
 function TJSONArray.GetAsJSON: TJSONStringType;
 function TJSONArray.GetAsJSON: TJSONStringType;
@@ -1074,7 +1273,7 @@ begin
                      else
                      else
                        Result:=TJSONNull.Create;
                        Result:=TJSONNull.Create;
       vtCurrency   : Result:=TJSONFloatNumber.Create(vCurrency^);
       vtCurrency   : Result:=TJSONFloatNumber.Create(vCurrency^);
-      vtInt64      : Result:=TJSONFloatNumber.Create(vInt64^);
+      vtInt64      : Result:=TJSONInt64Number.Create(vInt64^);
       vtObject     : if (VObject is TJSONData) then
       vtObject     : if (VObject is TJSONData) then
                        Result:=TJSONData(VObject)
                        Result:=TJSONData(VObject)
                      else
                      else
@@ -1147,6 +1346,11 @@ begin
   Result:=Add(TJSONIntegerNumber.Create(I));
   Result:=Add(TJSONIntegerNumber.Create(I));
 end;
 end;
 
 
+function TJSONArray.Add(I: Int64): Int64;
+begin
+  Result:=Add(TJSONInt64Number.Create(I));
+end;
+
 function TJSONArray.Add(S: String): Integer;
 function TJSONArray.Add(S: String): Integer;
 begin
 begin
   Result:=Add(TJSONString.Create(S));
   Result:=Add(TJSONString.Create(S));
@@ -1218,6 +1422,11 @@ begin
   Result:=GetElements(AName).AsInteger;
   Result:=GetElements(AName).AsInteger;
 end;
 end;
 
 
+function TJSONObject.GetInt64s(AName : String): Int64;
+begin
+  Result:=GetElements(AName).AsInt64;
+end;
+
 function TJSONObject.GetIsNull(AName : String): Boolean;
 function TJSONObject.GetIsNull(AName : String): Boolean;
 begin
 begin
   Result:=GetElements(AName).IsNull;
   Result:=GetElements(AName).IsNull;
@@ -1276,6 +1485,11 @@ begin
   SetElements(AName,TJSONIntegerNumber.Create(AVAlue));
   SetElements(AName,TJSONIntegerNumber.Create(AVAlue));
 end;
 end;
 
 
+procedure TJSONObject.SetInt64s(AName : String; const AValue: Int64);
+begin
+  SetElements(AName,TJSONInt64Number.Create(AVAlue));
+end;
+
 procedure TJSONObject.SetIsNull(AName : String; const AValue: Boolean);
 procedure TJSONObject.SetIsNull(AName : String; const AValue: Boolean);
 begin
 begin
   If Not AValue then
   If Not AValue then
@@ -1317,6 +1531,11 @@ begin
   ConvertError(True);
   ConvertError(True);
 end;
 end;
 
 
+function TJSONObject.GetAsInt64: Int64;
+begin
+  ConvertError(True);
+end;
+
 procedure TJSONObject.SetAsBoolean(const AValue: Boolean);
 procedure TJSONObject.SetAsBoolean(const AValue: Boolean);
 begin
 begin
   ConvertError(False);
   ConvertError(False);
@@ -1331,6 +1550,11 @@ procedure TJSONObject.SetAsInteger(const AValue: Integer);
 begin
 begin
   ConvertError(False);
   ConvertError(False);
 end;
 end;
+
+procedure TJSONObject.SetAsInt64(const AValue: Int64);
+begin
+  ConvertError(False);
+end;
 {$warnings on}
 {$warnings on}
 
 
 function TJSONObject.GetAsJSON: TJSONStringType;
 function TJSONObject.GetAsJSON: TJSONStringType;
@@ -1498,6 +1722,11 @@ begin
   Result:=Add(AName,TJSONIntegerNumber.Create(AValue));
   Result:=Add(AName,TJSONIntegerNumber.Create(AValue));
 end;
 end;
 
 
+function TJSONObject.Add(const AName: TJSONStringType; Avalue: Int64): Integer;
+begin
+  Result:=Add(AName,TJSONInt64Number.Create(AValue));
+end;
+
 function TJSONObject.Add(const AName: TJSONStringType): Integer;
 function TJSONObject.Add(const AName: TJSONStringType): Integer;
 begin
 begin
   Result:=Add(AName,TJSONNull.Create);
   Result:=Add(AName,TJSONNull.Create);

+ 53 - 0
packages/fcl-json/src/jsonconf.pp

@@ -83,15 +83,18 @@ type
 
 
     function  GetValue(const APath: WideString; const ADefault: WideString): WideString; overload;
     function  GetValue(const APath: WideString; const ADefault: WideString): WideString; overload;
     function  GetValue(const APath: WideString; ADefault: Integer): Integer; overload;
     function  GetValue(const APath: WideString; ADefault: Integer): Integer; overload;
+    function  GetValue(const APath: WideString; ADefault: Int64): Int64; overload;
     function  GetValue(const APath: WideString; ADefault: Boolean): Boolean; overload;
     function  GetValue(const APath: WideString; ADefault: Boolean): Boolean; overload;
     function  GetValue(const APath: WideString; ADefault: Double): Double; overload;
     function  GetValue(const APath: WideString; ADefault: Double): Double; overload;
     procedure SetValue(const APath: WideString; const AValue: WideString); overload;
     procedure SetValue(const APath: WideString; const AValue: WideString); overload;
     procedure SetValue(const APath: WideString; AValue: Integer); overload;
     procedure SetValue(const APath: WideString; AValue: Integer); overload;
+    procedure SetValue(const APath: WideString; AValue: Int64); overload;
     procedure SetValue(const APath: WideString; AValue: Boolean); overload;
     procedure SetValue(const APath: WideString; AValue: Boolean); overload;
     procedure SetValue(const APath: WideString; AValue: Double); overload;
     procedure SetValue(const APath: WideString; AValue: Double); overload;
 
 
     procedure SetDeleteValue(const APath: WideString; const AValue, DefValue: WideString); overload;
     procedure SetDeleteValue(const APath: WideString; const AValue, DefValue: WideString); overload;
     procedure SetDeleteValue(const APath: WideString; AValue, DefValue: Integer); overload;
     procedure SetDeleteValue(const APath: WideString; AValue, DefValue: Integer); overload;
+    procedure SetDeleteValue(const APath: WideString; AValue, DefValue: Int64); overload;
     procedure SetDeleteValue(const APath: WideString; AValue, DefValue: Boolean); overload;
     procedure SetDeleteValue(const APath: WideString; AValue, DefValue: Boolean); overload;
 
 
     procedure DeletePath(const APath: WideString);
     procedure DeletePath(const APath: WideString);
@@ -284,6 +287,20 @@ begin
     Result:=StrToIntDef(El.AsString,ADefault);
     Result:=StrToIntDef(El.AsString,ADefault);
 end;
 end;
 
 
+function TJSONConfig.GetValue(const APath: WideString; ADefault: Int64): Int64;
+var
+  El : TJSONData;
+
+begin
+  El:=FindElement(StripSlash(APath),False);
+  If Not Assigned(el) then
+    Result:=ADefault
+  else if (el is TJSONNumber) then
+    Result:=El.AsInt64
+  else
+    Result:=StrToInt64Def(El.AsString,ADefault);
+end;
+
 function TJSONConfig.GetValue(const APath: WideString; ADefault: Boolean): Boolean;
 function TJSONConfig.GetValue(const APath: WideString; ADefault: Boolean): Boolean;
 
 
 var
 var
@@ -376,6 +393,33 @@ begin
   FModified:=True;
   FModified:=True;
 end;
 end;
 
 
+procedure TJSONConfig.SetValue(const APath: WideString; AValue: Int64);
+
+var
+  El : TJSONData;
+  ElName : WideString;
+  O : TJSONObject;
+  I : integer;
+
+begin
+  El:=FindElement(StripSlash(APath),True,O,ElName);
+  if Assigned(El) and (Not (El is TJSONInt64Number)) then
+    begin
+    I:=O.IndexOfName(elName);
+    If (I<>-1) then // Normally not needed...
+      O.Delete(i);
+    El:=Nil;
+    end;
+  If Not Assigned(el) then
+    begin
+    El:=TJSONInt64Number.Create(AValue);
+    O.Add(ElName,El);
+    end
+  else
+    El.AsInt64:=AValue;
+  FModified:=True;
+end;
+
 procedure TJSONConfig.SetDeleteValue(const APath: WideString; AValue,
 procedure TJSONConfig.SetDeleteValue(const APath: WideString; AValue,
   DefValue: Integer);
   DefValue: Integer);
 begin
 begin
@@ -385,6 +429,15 @@ begin
     SetValue(APath, AValue);
     SetValue(APath, AValue);
 end;
 end;
 
 
+procedure TJSONConfig.SetDeleteValue(const APath: WideString; AValue,
+  DefValue: Int64);
+begin
+  if AValue = DefValue then
+    DeleteValue(APath)
+  else
+    SetValue(APath, AValue);
+end;
+
 procedure TJSONConfig.SetValue(const APath: WideString; AValue: Boolean);
 procedure TJSONConfig.SetValue(const APath: WideString; AValue: Boolean);
 
 
 var
 var

+ 4 - 1
packages/fcl-json/src/jsonparser.pp

@@ -127,13 +127,16 @@ Function TJSONParser.ParseNumber : TJSONNumber;
 
 
 Var
 Var
   I : Integer;
   I : Integer;
+  I64 : Int64;
   F : TJSONFloat;
   F : TJSONFloat;
   S : String;
   S : String;
 
 
 begin
 begin
   S:=CurrentTokenString;
   S:=CurrentTokenString;
   I:=0;
   I:=0;
-  If TryStrToInt(S,I) then
+  If TryStrToInt64(S,I64) then
+    Result:=TJSONInt64Number.Create(I64)
+  Else If TryStrToInt(S,I) then
     Result:=TJSONIntegerNumber.Create(I)
     Result:=TJSONIntegerNumber.Create(I)
   else
   else
     begin
     begin

+ 4 - 1
packages/fcl-json/tests/jsonconftest.pp

@@ -48,10 +48,11 @@ end;
 procedure TTestJSONConfig.TestDataTypes;
 procedure TTestJSONConfig.TestDataTypes;
 
 
 Const
 Const
-  A = 1;
+  A = Integer(1);
   B = 'A string';
   B = 'A string';
   C = 1.23;
   C = 1.23;
   D = True;
   D = True;
+  E = Int64($FFFFFFFFFFFFF);
 
 
 Var
 Var
   Co : TJSONCOnfig;
   Co : TJSONCOnfig;
@@ -67,6 +68,8 @@ begin
     AssertEquals('Float read/Write',c,Co.GetValue('c',0.0),0.01);
     AssertEquals('Float read/Write',c,Co.GetValue('c',0.0),0.01);
     Co.SetValue('d',d);
     Co.SetValue('d',d);
     AssertEquals('Boolean read/Write',d,Co.GetValue('d',False));
     AssertEquals('Boolean read/Write',d,Co.GetValue('d',False));
+    Co.SetValue('e',E);
+    AssertEquals('Int64 read/Write',e,Co.GetValue('e',Int64(0)));
     Co.Flush;
     Co.Flush;
   finally
   finally
     DeleteConf(Co,True);
     DeleteConf(Co,True);

+ 170 - 14
packages/fcl-json/tests/testjsondata.pp

@@ -45,6 +45,7 @@ type
     Procedure TestIsNull(J : TJSONData;Expected : Boolean);
     Procedure TestIsNull(J : TJSONData;Expected : Boolean);
     Procedure TestAsBoolean(J : TJSONData;Expected : Boolean; ExpectError : boolean = False);
     Procedure TestAsBoolean(J : TJSONData;Expected : Boolean; ExpectError : boolean = False);
     Procedure TestAsInteger(J : TJSONData; Expected : Integer; ExpectError : boolean = False);
     Procedure TestAsInteger(J : TJSONData; Expected : Integer; ExpectError : boolean = False);
+    Procedure TestAsInt64(J : TJSONData; Expected : Int64; ExpectError : boolean = False);
     Procedure TestAsString(J : TJSONData; Expected : String; ExpectError : boolean = False);
     Procedure TestAsString(J : TJSONData; Expected : String; ExpectError : boolean = False);
     Procedure TestAsFloat(J : TJSONData; Expected : TJSONFloat; ExpectError : boolean = False);
     Procedure TestAsFloat(J : TJSONData; Expected : TJSONFloat; ExpectError : boolean = False);
   end;
   end;
@@ -74,6 +75,17 @@ type
     procedure TestNegative;
     procedure TestNegative;
     procedure TestZero;
     procedure TestZero;
   end;
   end;
+
+  { TTestInt64 }
+
+  TTestInt64 = class(TTestJSON)
+  Private
+    Procedure DoTest(I : Int64);
+  published
+    procedure TestPositive;
+    procedure TestNegative;
+    procedure TestZero;
+  end;
   
   
   { TTestFloat }
   { TTestFloat }
 
 
@@ -121,6 +133,7 @@ type
     procedure TestCreateNilPointer;
     procedure TestCreateNilPointer;
     procedure TestCreatePointer;
     procedure TestCreatePointer;
     procedure TestAddInteger;
     procedure TestAddInteger;
+    procedure TestAddInt64;
     procedure TestAddFloat;
     procedure TestAddFloat;
     procedure TestAddBooleanTrue;
     procedure TestAddBooleanTrue;
     procedure TestAddBooleanFalse;
     procedure TestAddBooleanFalse;
@@ -152,6 +165,7 @@ type
     procedure TestCreateNilPointer;
     procedure TestCreateNilPointer;
     procedure TestCreatePointer;
     procedure TestCreatePointer;
     procedure TestAddInteger;
     procedure TestAddInteger;
+    procedure TestAddInt64;
     procedure TestAddFloat;
     procedure TestAddFloat;
     procedure TestAddBooleanTrue;
     procedure TestAddBooleanTrue;
     procedure TestAddBooleanFalse;
     procedure TestAddBooleanFalse;
@@ -255,6 +269,40 @@ begin
     end;
     end;
 end;
 end;
 
 
+procedure TTestJSON.TestAsInt64(J: TJSONData; Expected: Int64;
+  ExpectError: boolean);
+
+Var
+  I : Int64;
+  AssignOK : Boolean;
+  Msg : String;
+
+begin
+  AssignOK:=False;
+  Try
+    I:=J.AsInt64;
+    AssignOK:=True;
+    If Not ExpectError then
+      AssertEquals(J.Classname+'.AsInt64',Expected,I);
+  except
+    On E : Exception do
+      begin
+      AssignOK:=False;
+      Msg:=E.Message;
+      end;
+  end;
+  If ExpectError then
+    begin
+    If AssignOK then
+      Fail(J.ClassName+'.AsInt64 must raise error');
+    end
+  else
+    begin
+    If not AssignOK then
+      Fail(J.ClassName+'.AsInt64 raised unexpected exception: '+Msg)
+    end;
+end;
+
 procedure TTestJSON.TestAsString(J: TJSONData; Expected: String;
 procedure TTestJSON.TestAsString(J: TJSONData; Expected: String;
   ExpectError: boolean);
   ExpectError: boolean);
   
   
@@ -339,6 +387,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,True);
     TestAsBoolean(J,True);
     TestAsInteger(J,1);
     TestAsInteger(J,1);
+    TestAsInt64(J,1);
     TestAsString(J,BoolToStr(True));
     TestAsString(J,BoolToStr(True));
     TestAsFloat(J,1.0);
     TestAsFloat(J,1.0);
   finally
   finally
@@ -360,6 +409,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,False);
     TestAsBoolean(J,False);
     TestAsInteger(J,0);
     TestAsInteger(J,0);
+    TestAsInt64(J,0);
     TestAsString(J,BoolToStr(False));
     TestAsString(J,BoolToStr(False));
     TestAsFloat(J,0.0);
     TestAsFloat(J,0.0);
   finally
   finally
@@ -385,6 +435,7 @@ begin
     TestIsNull(J,True);
     TestIsNull(J,True);
     TestAsBoolean(J,False,True);
     TestAsBoolean(J,False,True);
     TestAsInteger(J,0,true);
     TestAsInteger(J,0,true);
+    TestAsInt64(J,0,true);
     TestAsString(J,BoolToStr(False),true);
     TestAsString(J,BoolToStr(False),true);
     TestAsFloat(J,0.0,true);
     TestAsFloat(J,0.0,true);
   finally
   finally
@@ -412,6 +463,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,False,True);
     TestAsBoolean(J,False,True);
     TestAsInteger(J,0,true);
     TestAsInteger(J,0,true);
+    TestAsInt64(J,0,true);
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,0.0,true);
     TestAsFloat(J,0.0,true);
   finally
   finally
@@ -436,6 +488,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,True,False);
     TestAsBoolean(J,True,False);
     TestAsInteger(J,1,False);
     TestAsInteger(J,1,False);
+    TestAsInt64(J,1,False);
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,1.0,False);
     TestAsFloat(J,1.0,False);
   finally
   finally
@@ -460,6 +513,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,True,False);
     TestAsBoolean(J,True,False);
     TestAsInteger(J,-1,False);
     TestAsInteger(J,-1,False);
+    TestAsInt64(J,-1,False);
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,-1.0,False);
     TestAsFloat(J,-1.0,False);
   finally
   finally
@@ -503,6 +557,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,True,False);
     TestAsBoolean(J,True,False);
     TestAsInteger(J,-1,True);
     TestAsInteger(J,-1,True);
+    TestAsInt64(J,-1,True);
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,-1.0,True);
     TestAsFloat(J,-1.0,True);
   finally
   finally
@@ -527,6 +582,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,False,False);
     TestAsBoolean(J,False,False);
     TestAsInteger(J,0,True);
     TestAsInteger(J,0,True);
+    TestAsInt64(J,0,True);
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,0,True);
     TestAsFloat(J,0,True);
   finally
   finally
@@ -548,6 +604,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,(F<>0),Not OK);
     TestAsBoolean(J,(F<>0),Not OK);
     TestAsInteger(J,Round(F),(Pos('.',S)<>0) or (Pos('E',UpperCase(S))<>0));
     TestAsInteger(J,Round(F),(Pos('.',S)<>0) or (Pos('E',UpperCase(S))<>0));
+    TestAsInt64(J,Round(F),(Pos('.',S)<>0) or (Pos('E',UpperCase(S))<>0));
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,F,Not OK);
     TestAsFloat(J,F,Not OK);
   finally
   finally
@@ -573,6 +630,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,(I<>0));
     TestAsBoolean(J,(I<>0));
     TestAsInteger(J,I);
     TestAsInteger(J,I);
+    TestAsInt64(J,I);
     TestAsString(J,IntToStr(I));
     TestAsString(J,IntToStr(I));
     TestAsFloat(J,I);
     TestAsFloat(J,I);
   finally
   finally
@@ -596,6 +654,47 @@ begin
   DoTest(0);
   DoTest(0);
 end;
 end;
 
 
+{ TTestInt64 }
+
+procedure TTestInt64.DoTest(I: Int64);
+
+Var
+  J : TJSONInt64Number;
+
+begin
+  J:=TJSONInt64Number.Create(I);
+  try
+    TestJSONType(J,jtNumber);
+    TestItemCount(J,0);
+    AssertEquals('Numbertype is ntInt64',ord(ntInt64),Ord(J.NumberType));
+    TestJSON(J,IntToStr(i));
+    TestIsNull(J,False);
+    TestAsBoolean(J,(I<>0));
+    TestAsInteger(J,I);
+    TestAsInt64(J,I);
+    TestAsString(J,IntToStr(I));
+    TestAsFloat(J,I);
+  finally
+    FreeAndNil(J);
+  end;
+end;
+
+procedure TTestInt64.TestPositive;
+
+begin
+  DoTest(1);
+end;
+
+procedure TTestInt64.TestNegative;
+begin
+  DoTest(-1);
+end;
+
+procedure TTestInt64.TestZero;
+begin
+  DoTest(0);
+end;
+
 { TTestFloat }
 { TTestFloat }
 
 
 procedure TTestFloat.DoTest(F: TJSONFloat);
 procedure TTestFloat.DoTest(F: TJSONFloat);
@@ -615,6 +714,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,(F<>0));
     TestAsBoolean(J,(F<>0));
     TestAsInteger(J,Round(F));
     TestAsInteger(J,Round(F));
+    TestAsInt64(J,Round(F));
     TestAsString(J,S);
     TestAsString(J,S);
     TestAsFloat(J,F);
     TestAsFloat(J,F);
   finally
   finally
@@ -663,6 +763,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,False,True);
     TestAsBoolean(J,False,True);
     TestAsInteger(J,1,True);
     TestAsInteger(J,1,True);
+    TestAsInt64(J,1,True);
     TestAsString(J,'',True);
     TestAsString(J,'',True);
     TestAsFloat(J,0.0,True);
     TestAsFloat(J,0.0,True);
   finally
   finally
@@ -780,12 +881,10 @@ end;
 procedure TTestArray.TestCreateInt64;
 procedure TTestArray.TestCreateInt64;
 
 
 Const
 Const
-  S : Int64 = $FFFFFF;
+  S : Int64 = $FFFFFFFFFFFFF;
 
 
 Var
 Var
   J : TJSONArray;
   J : TJSONArray;
-  r : String;
-  F : TJSONFloat;
 
 
 begin
 begin
   J:=TJSonArray.Create([S]);
   J:=TJSonArray.Create([S]);
@@ -793,9 +892,7 @@ begin
     TestJSONType(J,jtArray);
     TestJSONType(J,jtArray);
     TestItemCount(J,1);
     TestItemCount(J,1);
     TestJSONType(J[0],jtNumber);
     TestJSONType(J[0],jtNumber);
-    F:=S;
-    Str(F,R);
-    TestJSON(J,'['+R+']');
+    TestJSON(J,'['+IntToStr(S)+']');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
   end;
   end;
@@ -920,13 +1017,36 @@ Var
 begin
 begin
   J:=TJSonArray.Create;
   J:=TJSonArray.Create;
   try
   try
-    J.Add(0);
+    J.Add(Integer(0));
     TestItemCount(J,1);
     TestItemCount(J,1);
     TestJSONType(J[0],jtNumber);
     TestJSONType(J[0],jtNumber);
     AssertEquals('J[0] is TJSONIntegerNumber',J[0].ClassType,TJSONIntegerNumber);
     AssertEquals('J[0] is TJSONIntegerNumber',J[0].ClassType,TJSONIntegerNumber);
     AssertEquals('j.Types[0]=jtNumber',ord(J.Types[0]),Ord(jtNumber));
     AssertEquals('j.Types[0]=jtNumber',ord(J.Types[0]),Ord(jtNumber));
     AssertEquals('J.Integers[0]=0',0,J.integers[0]);
     AssertEquals('J.Integers[0]=0',0,J.integers[0]);
     TestAsInteger(J[0],0);
     TestAsInteger(J[0],0);
+    TestAsInt64(J[0],0);
+    TestJSON(J,'[0]');
+  finally
+    FreeAndNil(J);
+  end;
+end;
+
+procedure TTestArray.TestAddInt64;
+
+Var
+  J : TJSONArray;
+
+begin
+  J:=TJSonArray.Create;
+  try
+    J.Add(Int64(0));
+    TestItemCount(J,1);
+    TestJSONType(J[0],jtNumber);
+    AssertEquals('J[0] is TJSONInt64Number',J[0].ClassType,TJSONInt64Number);
+    AssertEquals('j.Types[0]=jtNumber',ord(J.Types[0]),Ord(jtNumber));
+    AssertEquals('J.Int64s[0]=0',0,J.Int64s[0]);
+    TestAsInteger(J[0],0);
+    TestAsInt64(J[0],0);
     TestJSON(J,'[0]');
     TestJSON(J,'[0]');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1057,6 +1177,8 @@ begin
     AssertEquals('J.Arrays[0] is TJSONArray',TJSONArray,J.Arrays[0].ClassType);
     AssertEquals('J.Arrays[0] is TJSONArray',TJSONArray,J.Arrays[0].ClassType);
     TestAsInteger(J.Arrays[0][0],0);
     TestAsInteger(J.Arrays[0][0],0);
     TestAsInteger(J.Arrays[0][1],1);
     TestAsInteger(J.Arrays[0][1],1);
+    TestAsInt64(J.Arrays[0][0],0);
+    TestAsInt64(J.Arrays[0][1],1);
     TestJSON(J,'[[0, 1]]');
     TestJSON(J,'[[0, 1]]');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1086,6 +1208,8 @@ begin
     AssertEquals('J.Objects[0] is TJSONObject',TJSONObject,J.Objects[0].ClassType);
     AssertEquals('J.Objects[0] is TJSONObject',TJSONObject,J.Objects[0].ClassType);
     TestAsInteger(J.Objects[0][A],0);
     TestAsInteger(J.Objects[0][A],0);
     TestAsInteger(J.Objects[0][B],1);
     TestAsInteger(J.Objects[0][B],1);
+    TestAsInt64(J.Objects[0][A],0);
+    TestAsInt64(J.Objects[0][B],1);
     TestJSON(J,'[{ "a" : 0, "b" : 1 }]');
     TestJSON(J,'[{ "a" : 0, "b" : 1 }]');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1137,6 +1261,8 @@ begin
     TestItemCount(J,2);
     TestItemCount(J,2);
     TestAsInteger(J[0],0);
     TestAsInteger(J[0],0);
     TestAsInteger(J[1],2);
     TestAsInteger(J[1],2);
+    TestAsInt64(J[0],0);
+    TestAsInt64(J[1],2);
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
   end;
   end;
@@ -1158,6 +1284,7 @@ begin
     TestIsNull(J,False);
     TestIsNull(J,False);
     TestAsBoolean(J,False,True);
     TestAsBoolean(J,False,True);
     TestAsInteger(J,1,True);
     TestAsInteger(J,1,True);
+    TestAsInt64(J,1,True);
     TestAsString(J,'',True);
     TestAsString(J,'',True);
     TestAsFloat(J,0.0,True);
     TestAsFloat(J,0.0,True);
   finally
   finally
@@ -1176,13 +1303,39 @@ Var
 begin
 begin
   J:=TJSonObject.Create;
   J:=TJSonObject.Create;
   try
   try
-    J.Add(A,0);
+    J.Add(A,Integer(0));
     TestItemCount(J,1);
     TestItemCount(J,1);
     TestJSONType(J[A],jtNumber);
     TestJSONType(J[A],jtNumber);
     AssertEquals('J[''a''] is TJSONIntegerNumber',J[A].ClassType,TJSONIntegerNumber);
     AssertEquals('J[''a''] is TJSONIntegerNumber',J[A].ClassType,TJSONIntegerNumber);
     AssertEquals('j.Types[''a'']=jtNumber',ord(J.Types[A]),Ord(jtNumber));
     AssertEquals('j.Types[''a'']=jtNumber',ord(J.Types[A]),Ord(jtNumber));
     AssertEquals('J.Integers[''a'']=0',0,J.integers[A]);
     AssertEquals('J.Integers[''a'']=0',0,J.integers[A]);
     TestAsInteger(J[A],0);
     TestAsInteger(J[A],0);
+    TestAsInt64(J[A],0);
+    TestJSON(J,'{ "'+A+'" : 0 }');
+  finally
+    FreeAndNil(J);
+  end;
+end;
+
+procedure TTestObject.TestAddInt64;
+
+Const
+  A = 'a';
+
+Var
+  J : TJSONObject;
+
+begin
+  J:=TJSonObject.Create;
+  try
+    J.Add(A,Int64(0));
+    TestItemCount(J,1);
+    TestJSONType(J[A],jtNumber);
+    AssertEquals('J[''a''] is TJSONInt64Number',J[A].ClassType,TJSONInt64Number);
+    AssertEquals('j.Types[''a'']=jtNumber',ord(J.Types[A]),Ord(jtNumber));
+    AssertEquals('J.Int64s[''a'']=0',0,J.Int64s[A]);
+    TestAsInteger(J[A],0);
+    TestAsInt64(J[A],0);
     TestJSON(J,'{ "'+A+'" : 0 }');
     TestJSON(J,'{ "'+A+'" : 0 }');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1330,6 +1483,8 @@ begin
     AssertEquals('J.Objects[''a''] is TJSONObject',TJSONObject,J.Objects[A].ClassType);
     AssertEquals('J.Objects[''a''] is TJSONObject',TJSONObject,J.Objects[A].ClassType);
     TestAsInteger(J.Objects[A][B],0);
     TestAsInteger(J.Objects[A][B],0);
     TestAsInteger(J.Objects[A][C],1);
     TestAsInteger(J.Objects[A][C],1);
+    TestAsInt64(J.Objects[A][B],0);
+    TestAsInt64(J.Objects[A][C],1);
     TestJSON(J,'{ "a" : { "b" : 0, "c" : 1 } }');
     TestJSON(J,'{ "a" : { "b" : 0, "c" : 1 } }');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1358,6 +1513,8 @@ begin
     AssertEquals('J.Arrays[0] is TJSONArray',TJSONArray,J.Arrays[A].ClassType);
     AssertEquals('J.Arrays[0] is TJSONArray',TJSONArray,J.Arrays[A].ClassType);
     TestAsInteger(J.Arrays[A][0],0);
     TestAsInteger(J.Arrays[A][0],0);
     TestAsInteger(J.Arrays[A][1],1);
     TestAsInteger(J.Arrays[A][1],1);
+    TestAsInt64(J.Arrays[A][0],0);
+    TestAsInt64(J.Arrays[A][1],1);
     TestJSON(J,'{ "a" : [0, 1] }');
     TestJSON(J,'{ "a" : [0, 1] }');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
@@ -1418,6 +1575,8 @@ begin
     TestItemCount(J,2);
     TestItemCount(J,2);
     TestAsInteger(J[a],1);
     TestAsInteger(J[a],1);
     TestAsInteger(J[c],3);
     TestAsInteger(J[c],3);
+    TestAsInt64(J[a],1);
+    TestAsInt64(J[c],3);
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
   end;
   end;
@@ -1541,12 +1700,10 @@ procedure TTestObject.TestCreateInt64;
 
 
 Const
 Const
   A = 'A';
   A = 'A';
-  S : Int64 = $FFFFFF;
+  S : Int64 = $FFFFFFFFFFFFF;
 
 
 Var
 Var
   J : TJSONObject;
   J : TJSONObject;
-  r : String;
-  F : TJSONFloat;
 
 
 begin
 begin
   J:=TJSONObject.Create([A,S]);
   J:=TJSONObject.Create([A,S]);
@@ -1554,9 +1711,7 @@ begin
     TestJSONType(J,jtObject);
     TestJSONType(J,jtObject);
     TestItemCount(J,1);
     TestItemCount(J,1);
     TestJSONType(J[A],jtNumber);
     TestJSONType(J[A],jtNumber);
-    F:=S;
-    Str(F,R);
-    TestJSON(J,'{ "A" : '+R+' }');
+    TestJSON(J,'{ "A" : '+IntToStr(S)+' }');
   finally
   finally
     FreeAndNil(J);
     FreeAndNil(J);
   end;
   end;
@@ -1792,6 +1947,7 @@ initialization
   RegisterTest(TTestNull);
   RegisterTest(TTestNull);
   RegisterTest(TTestBoolean);
   RegisterTest(TTestBoolean);
   RegisterTest(TTestInteger);
   RegisterTest(TTestInteger);
+  RegisterTest(TTestInt64);
   RegisterTest(TTestFloat);
   RegisterTest(TTestFloat);
   RegisterTest(TTestString);
   RegisterTest(TTestString);
   RegisterTest(TTestArray);
   RegisterTest(TTestArray);

+ 24 - 0
packages/fcl-json/tests/testjsonparser.pp

@@ -41,6 +41,7 @@ type
     procedure TestFalse;
     procedure TestFalse;
     procedure TestFloat;
     procedure TestFloat;
     procedure TestInteger;
     procedure TestInteger;
+    procedure TestInt64;
     procedure TestString;
     procedure TestString;
     procedure TestArray;
     procedure TestArray;
     procedure TestObject;
     procedure TestObject;
@@ -88,6 +89,26 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TTestParser.TestInt64;
+
+Var
+  P : TJSONParser;
+  J : TJSONData;
+
+begin
+  P:=TJSONParser.Create('123456789012345');
+  Try
+    J:=P.Parse;
+    If (J=Nil) then
+      Fail('Parse of 123456789012345 fails');
+    TestJSONType(J,jtNumber);
+    TestAsInt64(J,123456789012345);
+  Finally
+    FreeAndNil(J);
+    FreeAndNil(P);
+  end;
+end;
+
 procedure TTestParser.TestNull;
 procedure TTestParser.TestNull;
 
 
 Var
 Var
@@ -185,6 +206,9 @@ begin
   DoTestArray('[1]',1);
   DoTestArray('[1]',1);
   DoTestArray('[1, 2]',2);
   DoTestArray('[1, 2]',2);
   DoTestArray('[1, 2, 3]',3);
   DoTestArray('[1, 2, 3]',3);
+  DoTestArray('[1234567890123456]',1);
+  DoTestArray('[1234567890123456, 2234567890123456]',2);
+  DoTestArray('[1234567890123456, 2234567890123456, 3234567890123456]',3);
   Str(1.2,S1);
   Str(1.2,S1);
   Str(2.3,S2);
   Str(2.3,S2);
   Str(3.4,S3);
   Str(3.4,S3);