Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#7

AW: TJSONValue und Dezimalzahlen

  Alt 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;
  Mit Zitat antworten Zitat