4

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.

0

1 Answer 1

11

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.