我正在编写一个通用调用,用于通过JSON存储和检索数据.因此,当从JSON加载数据时,我可以验证它是TJSONNumber
,但缺乏正确的方法来确定它是integer
还是double
.目前我是这样做的,但我想还有更好的方法吗?
FDataStore: TDictionary<string, Variant>;
for index := 0 to Value.Count - 1 do begin
Pair := Value.Pairs[Index];
if Pair.JsonValue is TJSONNumber then
try
FDataStore.AddOrSetValue(Pair.JsonString.Value, (Pair.JsonValue as TJSONNumber).AsInt);
except
FDataStore.AddOrSetValue(Pair.JsonString.Value, (Pair.JsonValue as TJSONNumber).AsDouble);
end;
end;