How to parse a JSON string in Delphi?

后端 未结 5 957
太阳男子
太阳男子 2020-12-14 18:00

How can I parse the JSON string

{\"data\":{\"results\":[{\"Branch\":\"ACCT590003\"}]}}

using the T

5条回答
  •  无人及你
    2020-12-14 18:31

    You don't need to use external libraries to perform a JSONPath search. Example with Delphi 10 Seattle:

    uses  System.JSON;
    procedure ParseJSonValue;
    var
       JSonValue:TJSonValue;
       st:string;
       Branch: string;
    begin
       st := '{"data":{"results":[{"Branch":"ACCT590003"}]}}';
       JsonValue := TJSonObject.ParseJSONValue(st);
       Branch := JsonValue.GetValue('data.results[0].Branch');
       JsonValue.Free;
    end;
    

提交回复
热议问题