Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi JSONValue get value

Tags:

delphi

I have arrived up to here with my code:

JSONArray := TJSONObject.ParseJSONValue(Text) as TJSONArray;

for var JSONValue in JSONArray do
  begin
    ListBox1.Items.Add(JSONValue.Value);
  end;

Please note that Text := '[{"jahre":2},{"jahre":4},{"jahre":15}]' which is a valid JSON format. How can I get 2019 and 2018 items in the list?

With the above code I get white items in the list box.

like image 455
Rosanna Trevisan Avatar asked Sep 17 '25 02:09

Rosanna Trevisan


1 Answers

Each JSONValue is a "piece" of your array and each piece is an object. You have to convert the type to TJSONObject and the you can get the value.

ListBox1.Items.Add((JSONValue as TJSONObject).GetValue('jahre').ToString);

More info can be found in the doc (if you're using 10.3 the JSON library has been improved)

like image 68
Alberto Miola Avatar answered Sep 19 '25 07:09

Alberto Miola