zoukankan      html  css  js  c++  java
  • JSON解析

    //需要引入superobject单元,内容太多请联系本人获取

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
    IdHTTP, StdCtrls,msxml;

    type
    TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    private
    { Private declarations }
    public
    HttpReq: IXMLHttpRequest;
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    uses DateUtils,superobject;

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);
    var
    url: string;
    vJson: ISuperObject;
    begin
    HttpReq := CoXMLHTTPRequest.Create;
    url := 'http://www.weather.com.cn/weather/101120201.shtml';
    HttpReq.open('Get', Url, False, EmptyParam, EmptyParam);
    HttpReq.send(EmptyParam);//开始搜索
    Url := HttpReq.responseText;

    memo1.Lines.Add(url);
    exit;

    vjson:=so(url);
    Memo1.Lines.Clear;
    if vJson['weatherinfo'].AsString<>'' then
    begin
    vjson:=so(vJson['weatherinfo'].AsString);
    memo1.Lines.Add('城市:'+vJson['city'].AsString );
    Memo1.Lines.Add('今日天气('+vJson['date_y'].AsString+' '+vjson['week'].asstring+'):');
    Memo1.Lines.Add(' 温度:'+vjson['temp1'].asstring);
    Memo1.Lines.Add(' 天气:'+vjson['weather1'].asstring);
    Memo1.Lines.Add(' 风力:'+vjson['wind1'].asstring);

    Memo1.Lines.Add('明日天气('+FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now))+'):');
    Memo1.Lines.Add(' 温度:'+vjson['temp2'].asstring);
    Memo1.Lines.Add(' 天气:'+vjson['weather2'].asstring);
    Memo1.Lines.Add(' 风力:'+vjson['wind2'].asstring);

    Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,2))+':');
    Memo1.Lines.Add(' 温度:'+vjson['temp3'].asstring);
    Memo1.Lines.Add(' 天气:'+vjson['weather3'].asstring);
    Memo1.Lines.Add(' 风力:'+vjson['wind3'].asstring);

    Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,3))+':');
    Memo1.Lines.Add(' 温度:'+vjson['temp4'].asstring);
    Memo1.Lines.Add(' 天气:'+vjson['weather4'].asstring);
    Memo1.Lines.Add(' 风力:'+vjson['wind4'].asstring);

    Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,4))+':');
    Memo1.Lines.Add(' 温度:'+vjson['temp5'].asstring);
    Memo1.Lines.Add(' 天气:'+vjson['weather5'].asstring);
    Memo1.Lines.Add(' 风力:'+vjson['wind5'].asstring);
    end;
    end;

    end.

  • 相关阅读:
    “浪潮杯”第九届山东省ACM大学生程序设计竞赛 F: Four-tuples容斥定理
    B
    C. Tourist Problem 2021.3.29 晚vj拉题 cf 1600 纯数学题
    C. Sum of Cubes
    Day29、Python中的异常处理及元类
    isinstance,issubclass,反射,内置方法(__str__,__del__,__call__)
    绑定方法与非绑定方法;classmethod及staticmethod装饰器
    组合,多态,封装
    类的继承
    面向对象编程思想基本介绍,类与对象的基本使用,属性查找,绑定方法
  • 原文地址:https://www.cnblogs.com/zyb2016/p/6126523.html
Copyright © 2011-2022 走看看