Registriert seit: 6. Mär 2013
6.199 Beiträge
Delphi 10 Seattle Enterprise
|
AW: TJSONValue und Dezimalzahlen
16. Jul 2018, 09:24
So ungefähr?
Delphi-Quellcode:
type
TJsonObjectHelper = class helper for System.JSON.TJSONObject
function FindPair(const PairName: String): TJSONPair;
end;
procedure p();
const
input = '{"key": 123.400}';
var
jsonObject: TJSONObject;
jsonPair: TJSONPair;
begin
jsonObject := TJsonObject.ParseJSONValue(input) as TJSONObject;
try
jsonPair := jsonObject.FindPair('key');
WriteLn( jsonPair.JsonValue.ToString() ); // Ergibt "123.400"
finally
jsonObject.Destroy();
end;
end;
{ TJsonObjectHelper }
function TJsonObjectHelper.FindPair(const PairName: String): TJSONPair;
var
Candidate: TJSONPair;
I: Integer;
begin
for I := 0 to Count - 1 do
begin
Candidate := TJSONPair(self.FMembers[I]);
if (Candidate.JsonString.Value = PairName) then
begin
Exit(Candidate);
end;
end;
Result := nil;
end;
|
|
Zitat
|