I have a rest server returning the next json string:
response:='{"result":["[{\"email\":\"[email protected]\",\"regid\":\"12312312312312312313213w\"},{\"email\":\"[email protected]\",\"regid\":\"AAAAAAA\"}]"]}';
I´d like to parse the response to get a list of all email and regid items.
I have tried the next code but I am getting an AV at (TJSONPair(LItem).JsonString.Value='email')
Any help will be appreciated.
Thanks in advance, Luiz
var
LResult:TJSONArray;
LJsonresponse:TJSONObject;
i:integer;
LItem,jv:TJsonValue;
email,regid:string;
LJsonresponse:=TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(response),0) as TJSONObject;
LResult:=(LJsonresponse.GetValue('result') as TJSONArray);
jv:=TJSONArray(LResult.Get(0));
for LItem in TJSONArray(jv) do begin
if (TJSONPair(LItem).JsonString.Value='email') then begin
email:=TJSONPair(LItem).JsonValue.Value;
end;
if (TJSONPair(LItem).JsonString.Value='regid') then begin
regid:=TJSONPair(LItem).JsonValue.Value;
end;
end;