移动应用开发实验十 —— 网络通信

该实验旨在掌握网络请求和JSON数据解析,通过调用中国天气网接口获取北京、上海、杭州、广州的实时天气信息,并在Android app中展示。实验包括配置接口、解析接口返回的JSON数据及在app中显示天气结果。
摘要由CSDN通过智能技术生成

一、实验目的

掌握数据解析(以json为例)、网络请求的关键内容。

二、实验内容

1.接口示例(北京)http://www.weather.com.cn/data/sk/101010100.html
2.可选择和任意切换北京、杭州、广州、上海的天气(阴晴雨雪)、气温、湿度等。
3.解析json接口获取的数据。
4.在app中展现天气结果。

中国天气网地址:http://www.weather.com.cn
请求服务 : 查询实时天气信息
http://www.weather.com.cn/data/sk/101110101.html
其中101110101是城市的代码,如果要查询其他城市的天气,只需要修改城市的代码即可,在中国天气网中城市代码如下:
101010100=北京
101020100=上海
101210101=杭州
101280101=广州

三、实验过程(实验的设计思路、关键源代码等)

接口代码配置

public static final String Host_WEATHER="http://www.weather.com.cn";
@GET("/data/cityinfo/{cityId}.html")
Call<CityInfoWeather> getCityInfoWeather(@Path("cityId")String cityId);
@GET("/data/sk/{cityId}.html")
Call<SKWeather> getSKWeather(@Path("cityId")String cityId);

接口具体返回值详情
在这里插入图片描述

具体布局省略,根据个人意愿进行自定义布局
以下仅供参考
在这里插入图片描述
获取对应的气温,风向,湿度,天气情况等信息

public class SKWeather {
   
    private WeatherInfo weatherinfo;

    public WeatherInfo getWeatherInfo(){
   
        return weatherinfo;
    }
    public void setWeatherInfo(WeatherInfo weatherinfo){
   
        this.weatherinfo=weatherinfo;
    }
    public class WeatherInfo{
   
        private String temp;
        private String WD;
        private String SD;
        private String WS;
        private String Humidity;
        private String AP;
        public String getTemp(){
   return temp;}
        public void setTemp(String temp){
   this.temp=temp;}
        public String getWD(){
   return WD;}
        public void WD(String WD){
   this.WD=WD;}
        public String getSD(){
   return SD;}
        public void 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值