【发布时间】:2015-10-02 03:23:07
【问题描述】:
我有一个休息服务器返回下一个 json 字符串:
response:='{"result":["[{\"email\":\"XXX@gmail.com\",\"regid\":\"12312312312312312313213w\"},{\"email\":\"YYYY@gmail.com\",\"regid\":\"AAAAAAA\"}]"]}';
我想解析响应以获取所有 email 和 regid 项目的列表。
我已经尝试了下一个代码,但我在 (TJSONPair(LItem).JsonString.Value='email') 获得了一个 AV
任何帮助将不胜感激。
提前致谢,路易斯
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;
【问题讨论】:
标签: json delphi parsing delphi-xe