Home > Back-end >  Under DELPHI7 superobject reads Chinese weather net JSON data of weather forecast
Under DELPHI7 superobject reads Chinese weather net JSON data of weather forecast

Time:09-24

The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls IdBaseComponent, IdComponent IdTCPConnection,
IdTCPClient IdHTTP, StdCtrls, MSXML;

Type
TForm1=class (TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
HttpReq: IXMLHttpRequest;
end;



Var
Form1: TForm1;

Implementation
USES DateUtils superobject;
{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);
Var
Url: string;
VJson: ISuperObject;
The begin

HttpReq:=CoXMLHTTPRequest. Create;

Url:='http://m.weather.com.cn/data/101270401.html';
HttpReq. Open (' Get 'Url, False, EmptyParam, EmptyParam);
HttpReq. Send (EmptyParam);//search
Url:=HttpReq. The responseText;
Vjson:=so (url);

Memo1. Lines. The Clear;
If vJson [' weatherinfo] AsString<> "' then
The begin
Vjson:=so (vjson [' weatherinfo] AsString) are identical.
Memo1. Lines. The Add (' city: '+ vJson [' city'] AsString) are identical.
Memo1. Lines. The Add (' today's weather (' + vJson [' date_y] AsString + ' '+ vJson [' week'] AsString + ') : ");
Memo1. Lines. The Add (+ vjson 'temperature:' [' temp1 '] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'weather:' [' weather1] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'wind:' [' wind1] asstring) are identical.

Memo1. Lines. The Add (' the weather tomorrow (' + FormatDateTime (' on DD MM YYYY years' DateUtils. IncDay (now)) + ') : ");
Memo1. Lines. The Add (+ vjson 'temperature:' [' temp2] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'weather:' [' weather2] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'wind:' [' wind2] asstring) are identical.

Memo1. Lines. The Add (FormatDateTime (' on DD MM YYYY years' DateUtils. IncDay (now, 2)) + ', ');
Memo1. Lines. The Add (+ vjson 'temperature:' [' temp3] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'weather:' [' weather3] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'wind:' [' wind3] asstring) are identical.

Memo1. Lines. The Add (FormatDateTime (' on DD MM YYYY years' DateUtils. IncDay (now, 3)) + ', ');
Memo1. Lines. The Add (+ vjson 'temperature:' [' temp4] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'weather:' [' weather4] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'wind:' [' wind4] asstring) are identical.

Memo1. Lines. The Add (FormatDateTime (' on DD MM YYYY years' DateUtils. IncDay (now, 4)) + ', ');
Memo1. Lines. The Add (+ vjson 'temperature:' [' temp5] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'weather:' [' weather5] asstring) are identical.
Memo1. Lines. The Add (+ vjson 'wind:' [' wind5] asstring) are identical.
end;

end;


end.

CodePudding user response:

Take data with indy, HttpReq send message header with a value of 0 Content - Length, lead to take less than data,
And the Content - Length and delete not to drop, so still in indy!

CodePudding user response:

Using TIdHTTP data, no problem,


CodePudding user response:

What's the problem with this problem?

CodePudding user response:

[yabao=] [/yabao]

CodePudding user response:

Technology to share?
  • Related