当前位置:wayQQ空间站 > 电脑网络 > 文章内容

jsondelphi JSON解析,求代码?

网站:http://wayqq.cn┊类别:电脑网络┊时间:2018-08-15 15:12:37
json delphi

求解写下面JSON的代码,感谢。
{"error_code":0,"reason":"success","result":{"state":3,"uptime":"2018-08-13 21:39:14","data":[{"time":"2018-08-11 17:53:09","remark":"快件已签收,签收人是【本人】"},

{"time":"2018-08-11 08:18:10","remark":"[上海营业部]的【余鸿】正在派件, 电话:15800644202"},{"time":"2018-08-11 08:14:10","remark":"快件已到达[上海营业部],上一站是[上海营业

部]"},{"time":"2018-08-11 02:56:59","remark":"快件已由[上海分拨中心]发往[上海营业部]"},{"time":"2018-08-10 12:50:06","remark":"快件已由[上海分拨中心]发往[上海营业部]"},

{"time":"2018-08-10 12:29:04","remark":"[嘉定六部]的【嘉定六部】正在派件, 电话:13650531758"},{"time":"2018-08-10 11:53:06","remark":"快件已到达[上海分拨中心]"},{"time":"2018

-08-10 08:08:35","remark":"快件已由[嘉定六部]发往[上海分拨中心]"},{"time":"2018-08-10 08:03:44","remark":"快件已到达[嘉定六部],上一站是[上海分拨中心]"},{"time":"2018-08-10

02:39:12","remark":"快件已由[上海分拨中心]发往[嘉定六部]"},{"time":"2018-08-09 23:25:28","remark":"快件已到达[上海分拨中心],上一站是[嘉定三部]"},{"time":"2018-08-09

19:22:57","remark":"快件已由[嘉定六部]发往[上海分拨中心]"},{"time":"2018-08-09 19:22:56","remark":"[嘉定六部]【嘉定六部】已收件"},{"time":"2018-08-09 18:42:54","remark":"[嘉定

六部]【华超】已收件"}],"information":{"no":518704351463,"sName":"UC","expName":"UC优速快递","url":"http://www.uc56.com","tel":"400-1111-119","img":"https://oss-

cn2.apistore.cn/exp/UC.png"}},"ordersign":"20180813215900272775252910"}

推荐用QJSON解析, 用法简单, 解析速度还快, 通过SVN下载: svn://www.qdac.cc/QDAC3

对json内容结构部熟悉, 可以看接口文档, 或者找个json解析器看看, 比如 https://www.sojson.com/

这是我写的解析demo

 implementation

uses
  QJSON;

{$R *.dfm}

const
  JSONDATA = '{"error_code":0,"reason":"success","result":{"state":3,"uptime":"'
    + '2018-08-13 21:39:14","data":[{"time":"2018-08-11 17:53:09","remark":"快件'
    + '已签收,签收人是【本人】"},{"time":"2018-08-11 08:18:10","remark":"[上海'
    + '营业部]的【余鸿】正在派件, 电话:15800644202"},{"time":"2018-08-11 08:14:'
    + '10","remark":"快件已到达[上海营业部],上一站是[上海营业部]"},{"time":"2018'
    + '-08-11 02:56:59","remark":"快件已由[上海分拨中心]发往[上海营业部]"},{"tim'
    + 'e":"2018-08-10 12:50:06","remark":"快件已由[上海分拨中心]发往[上海营业部]'
    + '"},{"time":"2018-08-10 12:29:04","remark":"[嘉定六部]的【嘉定六部】正在派'
    + '件, 电话:13650531758"},{"time":"2018-08-10 11:53:06","remark":"快件已到'
    + '达[上海分拨中心]"},{"time":"2018-08-10 08:08:35","remark":"快件已由[嘉定'
    + '六部]发往[上海分拨中心]"},{"time":"2018-08-10 08:03:44","remark":"快件已'
    + '到达[嘉定六部],上一站是[上海分拨中心]"},{"time":"2018-08-1002:39:12","rem'
    + 'ark":"快件已由[上海分拨中心]发往[嘉定六部]"},{"time":"2018-08-09 23:25:28'
    + '","remark":"快件已到达[上海分拨中心],上一站是[嘉定三部]"},{"time":"2018-0'
    + '8-0919:22:57","remark":"快件已由[嘉定六部]发往[上海分拨中心]"},{"time":"2'
    + '018-08-09 19:22:56","remark":"[嘉定六部]【嘉定六部】已收件"},{"time":"201'
    + '8-08-09 18:42:54","remark":"[嘉定六部]【华超】已收件"}],"information":{"n'
    + 'o":518704351463,"sName":"UC","expName":"UC优速快递","url":"http://www.uc5'
    + '6.com","tel":"400-1111-119","img":"https://oss-cn2.apistore.cn/exp/UC.png'
    + '"}},"ordersign":"20180813215900272775252910"}';

procedure TForm1.Button1Click(Sender: TObject);
var
  nJ, nJInfo, nJR, nJRDS, nJRD: TQJson;
  nDataIndex: Integer;
begin
  Memo1.Lines.Clear;
  nJ := TQJson.Create;
  try
    nJ.Parse(JSONDATA);

    Memo1.Lines.Add('ErrorCode: ' + nJ.ItemByName('error_code').AsString);
    Memo1.Lines.Add('reason:' + nJ.ItemByName('reason').AsString);
    Memo1.Lines.Add('ordersign:' + nJ.ItemByName('ordersign').AsString);

    Memo1.Lines.Add('');
    nJR := nJ.ItemByName('result');
    Memo1.Lines.Add('state:' + nJR.ItemByName('state').AsString);
    Memo1.Lines.Add('uptime:' + nJR.ItemByName('uptime').AsString);

    Memo1.Lines.Add('');
    nJInfo := nJR.ItemByName('information');
    Memo1.Lines.Add('no:' + nJInfo.ItemByName('no').AsString);
    Memo1.Lines.Add('sName:' + nJInfo.ItemByName('sName').AsString);
    Memo1.Lines.Add('expName:' + nJInfo.ItemByName('expName').AsString);
    Memo1.Lines.Add('url:' + nJInfo.ItemByName('url').AsString);
    Memo1.Lines.Add('tel:' + nJInfo.ItemByName('tel').AsString);
    Memo1.Lines.Add('img:' + nJInfo.ItemByName('img').AsString);

    Memo1.Lines.Add('');
    Memo1.Lines.Add('Data:');
    nJRDS := nJR.ItemByName('data');
    for nDataIndex := 0 to nJRDS.Count - 1 do
    begin
      nJRD := nJRDS.Items[nDataIndex];
      Memo1.Lines.Add(Format('--> time:%s  remark:%s',
        [nJRD.ItemByName('time').AsString,
        nJRD.ItemByName('remark').AsString]));
    end;
  finally
    nJ.Free;
  end;
end;

这是解析结果

ErrorCode: 0
reason:success
ordersign:20180813215900272775252910

state:3
uptime:2018-08-13 21:39:14

no:518704351463
sName:UC
expName:UC优速快递
url:http://www.uc56.com
tel:400-1111-119
img:https://oss-cn2.apistore.cn/exp/UC.png

Data:
--> time:2018-08-11 17:53:09 remark:快件已签收,签收人是【本人】
--> time:2018-08-11 08:18:10 remark:[上海营业部]的【余鸿】正在派件, 电话:15800644202
--> time:2018-08-11 08:14:10 remark:快件已到达[上海营业部],上一站是[上海营业部]
--> time:2018-08-11 02:56:59 remark:快件已由[上海分拨中心]发往[上海营业部]
--> time:2018-08-10 12:50:06 remark:快件已由[上海分拨中心]发往[上海营业部]
--> time:2018-08-10 12:29:04 remark:[嘉定六部]的【嘉定六部】正在派件, 电话:13650531758
--> time:2018-08-10 11:53:06 remark:快件已到达[上海分拨中心]
--> time:2018-08-10 08:08:35 remark:快件已由[嘉定六部]发往[上海分拨中心]
--> time:2018-08-10 08:03:44 remark:快件已到达[嘉定六部],上一站是[上海分拨中心]
--> time:2018-08-1002:39:12 remark:快件已由[上海分拨中心]发往[嘉定六部]
--> time:2018-08-09 23:25:28 remark:快件已到达[上海分拨中心],上一站是[嘉定三部]
--> time:2018-08-0919:22:57 remark:快件已由[嘉定六部]发往[上海分拨中心]
--> time:2018-08-09 19:22:56 remark:[嘉定六部]【嘉定六部】已收件
--> time:2018-08-09 18:42:54 remark:[嘉定六部]【华超】已收件

为您推荐
精品图片推荐
关于本站 | 广告服务 | 版权声明 | 友情链接 | 网站地图 | 返回顶部
小刀娱乐网 qq资源网 小刀在线 爱上资源网 qq乐园 qq技术网站 小偷娱乐网 爱q生活网 爱q生活 qq技术乐园 qq业务乐园首页 钻石皇朝 小K娱乐网
WAYQQ空间站www.wayqq.cn 版权所有 Copyright © 2007-2018 QQ业务乐园. All Rights Reserved . 鄂ICP备12017691号 鄂公网安备42060202000014号