I'm trying to catch the following JSON array :
[{"name":"Bryan","email":"[email protected]"},
{"name":"Louis","email":"[email protected]"},
{"name":"Maria","email":"[email protected]"},
{"name":"Test","email":"[email protected]"},
{"name":"Anthony","email":"[email protected]"}]
and put it in Memo or ListBox in Delphi :
the code is the following :
procedure TForm1.Button1Click(Sender: TObject);
var jv: TJSONValue;
jo: TJSONObject;
jp: TJSONPair;
ja: TJSONArray;
i: integer;
j: integer;
begin
RESTRequest1.Execute;
jv:=RESTResponse1.JSONValue;
jo:= TJSONObject.ParseJSONValue(jv.ToString) as TJSONObject;
try
for i := 0 to jo.Size - 1 do
begin
jp := jo.Get(i);
if jp.JsonValue is TJSONArray then
begin
ja := jp.JsonValue as TJSONArray;
for j := 0 to ja.Size -1 do
Memo1.Lines.Add(ja.Get(i).ClassName + ': ' + ja.Get(j).ToString);
end
else
Memo1.Lines.Add(jp.ClassName + ': '+ jp.ToString);
end;
finally
jo.Free;
end;
end;
When I click in Button I got the following error message :
Invalid class typecast
during debugging the following line has a problem :
jo:= TJSONObject.ParseJSONValue(jv.ToString) as TJSONObject;
I don't know how to resolve this problem or this mistake , Could you please help me ?
Thanks.


TJSONObject.ParseJSONValue(jv.ToString)is not derived fromTJSONObject. Perhaps it isnil. You can debug this quite easily. If you wanted us to help you'd need to produce an MCVE. It would be very easy to do so. We don't have the REST. What we need is that value ofjv.ToString. You could make a 10 line MCVE for this. Learning how to debug is really your goal here. - David Heffernan{"Persons": <The array as standing above>}Works fine for me. - Teun Pronk