Delphi JSON 天气预报
来源:互联网 发布:梵高怎么得的精神 知乎 编辑:程序博客网 时间:2024/05/18 03:09
DELPHI7代码读取中国天气网JSON数据,实现一个天气预报程序,没有过多美化,只是简单的读取出了指定城市的天气信息,美化一下就是一款漂亮的天气预报软件了。需要了解中国天气网城市代码JSON 串格式和中国天气网城市代码 JSON 数组格式,这两个文件已附上,下载压缩包解压即可。首先下载:
产生下载FlashPlayerControl
主要代码:
procedure Getinidate;var inifile :TIniFile; ClientIniFile,Weatherid: string; i,p1 : Integer; idhttpweatherid: TIdHTTP; vJson:ISuperObject;begin i:= 0; ClientIniFile:= '.\config.ini'; inifile:= TIniFile.Create(ClientIniFile); Form1.SsityID :=inifile.ReadString('Weather','cityid','null');end;procedure TForm1.Button1Click(Sender: TObject);var vJson,vItem: ISuperObject; IdHTTP1: TIdHTTP; function getbg(TQ: string):Integer ; begin Result:= 1; if Pos('晴', TQ)>0 then Result:=1; if Pos('多云', TQ)>0 then Result:=2; if Pos('阴', TQ)>0 then Result:=3; if Pos('雨', TQ)>0 then Result:=4; if Pos('雷', TQ)>0 then Result:=5; if Pos('雪', TQ)>0 then Result:=7; if Pos('雾', TQ)>0 then Result:=8; if Pos('台', TQ)>0 then Result:=9; if Pos('沙', TQ)>0 then Result:=10; end;begin if not Button1.Enabled then Abort; Button1.Enabled:= False; IdHTTP1:= TIdHTTP.Create(nil); Getinidate;// MessageDlg(sSityID, mtInformation, [mbOK], 0); verPng:='999'; try vJson:=SO(IdHTTP1.Get('http://m.weather.com.cn/data/'+sSityID+'.html')); vItem :=SO(IdHTTP1.Get('http://www.weather.com.cn/data/sk/'+sSityID+'.html')); ImageJT.Picture.LoadFromFile('res\'+vJson['weatherinfo.img1'].AsString+'.png'); lblSS.Caption:=vJson['weatherinfo.week'].AsString+'(今天 实时 '+vItem['weatherinfo.temp'].AsString+'℃)'; LabelCity.Caption:= vJson['weatherinfo.city'].AsString; lbJTWD.Caption:=vJson['weatherinfo.temp1'].AsString; lblJTTQ.Caption:= vJson['weatherinfo.weather1'].AsString; lblJTFX.Caption:= vJson['weatherinfo.wind1'].AsString; Image5.Tag:= getbg(lblJTTQ.Caption);// MessageDlg('1', mtInformation, [mbOK], 0); imagew1.Picture.LoadFromFile('res\'+vJson['weatherinfo.img3'].AsString+'.png'); week1.Caption:=getweek((now)+1); lbLWD1.Caption:=vJson['weatherinfo.temp2'].AsString; lblTQ1.Caption:= vJson['weatherinfo.weather2'].AsString; LblFZ1.Caption:= vJson['weatherinfo.wind2'].AsString; image1.Tag:= getbg(lblTQ1.Caption); week2.Caption:=getweek((now)+2); imagew2.Picture.LoadFromFile('res\'+vJson['weatherinfo.img5'].AsString+'.png'); lbLWD2.Caption:=vJson['weatherinfo.temp3'].AsString; lblTQ2.Caption:= vJson['weatherinfo.weather3'].AsString; LblFZ2.Caption:= vJson['weatherinfo.wind3'].AsString; image2.Tag:= getbg(lblTQ2.Caption); week3.Caption:=getweek((now)+3); imagew3.Picture.LoadFromFile('res\'+vJson['weatherinfo.img7'].AsString+'.png'); lbLWD3.Caption:=vJson['weatherinfo.temp4'].AsString; lblTQ3.Caption:= vJson['weatherinfo.weather4'].AsString; LblFZ3.Caption:= vJson['weatherinfo.wind4'].AsString; image3.Tag:= getbg(lblTQ3.Caption); week4.Caption:=getweek((now)+4); imagew4.Picture.LoadFromFile('res\'+vJson['weatherinfo.img9'].AsString+'.png'); lbLWD4.Caption:=vJson['weatherinfo.temp5'].AsString; lblTQ4.Caption:= vJson['weatherinfo.weather5'].AsString; LblFZ4.Caption:= vJson['weatherinfo.wind5'].AsString; image4.Tag:= getbg(lblTQ4.Caption); IdHTTP1.Disconnect; except IdHTTP1.Disconnect; ImageJT.Picture.LoadFromFile('res\NA.png'); lblSS.Caption:=getweek(now)+'(今天 实时N/A℃)'; LabelCity.Caption:= '--'; lbJTWD.Caption:='N/A'; lblJTTQ.Caption:= 'N/A'; lblJTFX.Caption:= 'N/A'; Image5.Tag:= getbg(lblJTTQ.Caption); imagew1.Picture.LoadFromFile('res\NA.png'); week1.Caption:=getweek((now)+1); lbLWD1.Caption:= 'N/A'; lblTQ1.Caption:= 'N/A'; LblFZ1.Caption:= 'N/A'; image1.Tag:= getbg(lblTQ1.Caption); week2.Caption:=getweek((now)+2); imagew2.Picture.LoadFromFile('res\NA.png'); lbLWD2.Caption:= 'N/A'; lblTQ2.Caption:= 'N/A'; LblFZ2.Caption:= 'N/A'; image2.Tag:= getbg(lblTQ2.Caption); week3.Caption:=getweek((now)+3); imagew3.Picture.LoadFromFile('res\NA.png'); lbLWD3.Caption:= 'N/A'; lblTQ3.Caption:= 'N/A'; LblFZ3.Caption:= 'N/A'; image3.Tag:= getbg(lblTQ3.Caption); week4.Caption:=getweek((now)+4); imagew4.Picture.LoadFromFile('res\NA.png'); lbLWD4.Caption:= 'N/A'; lblTQ4.Caption:= 'N/A'; LblFZ4.Caption:= 'N/A'; image4.Tag:= getbg(lblTQ4.Caption); Button1.Enabled:= true; end; TransparentFlashPlayerControl1.Movie:= ExtractFilePath(Application.ExeName)+'WeatherSkin\'+inttostr(image5.Tag)+'\main.swf'; Button1.Enabled:= true;end;
- Delphi JSON 天气预报
- json解析天气预报
- webservice 天气预报 Json格式
- json天气预报解析
- JSON请求天气预报数据
- Json解析之天气预报
- Android天气预报(Json解析)
- delphi Indy 实现天气预报功能
- Delphi json
- delphi json
- Delphi json
- 使用Gson转化天气预报Json
- 网路:JSON 解析(天气预报)
- 用json获取天气预报信息
- JSON 解析 网络 上 天气预报
- Delphi 客户端调用WebService(天气预报)
- 提供JSON REST API的国内天气预报
- 国家气象局天气预报JSON数据接口详解
- excelDownload
- Android项目实战--手机卫士18--读取用户的短信内容以及短信备份
- 黑马程序员------Java的泛型(原理应用、自定义泛型)
- log4j:ERROR Could not instantiate class [org.apache.hadoop.hive.shims.HiveEventCounter].
- PowerDesigner 学习及使用
- Delphi JSON 天气预报
- 线程同步与互斥
- 温度PID的整定过程
- multipart/form-data和application/x-www-form-urlencoded
- Redis实战之征服 Redis + Jedis + Spring (三)
- 一个台阶总共有n级,如果一次可以跳1级,也可以跳2级。 //求总共有多少总跳法,并分析算法的时间复杂度
- Red5性能测试
- tar打印进度
- Qt5.1.1 MinGW48 release静态版编译结果分享