天气预报接口 20天(天气预报接口 json)

天气预报接口 20天(天气预报接口 json)天气查询 APP 两种 JSON 解析方式 原始 em json em 数据解析 JSON Object json Object new JSON Object res String reason json Object getString reason if reason

大家好,我是讯享网,很高兴认识大家。

天气查询APP,两种JSON解析方式


讯享网

 / * 原始<em>json</em>数据解析 * */ 

讯享网

// JSONObject jsonObject = new JSONObject(res); // String reason=jsonObject.getString(&quot;reason&quot;); // if (reason.equals(&quot;参数不正确&quot;)){ // handler.sendEmptyMessage(1); // return; // } // JSONObject result=jsonObject.getJSONObject(&quot;result&quot;); // JSONObject realtime=result.getJSONObject(&quot;realtime&quot;); // JSONObject life=result.getJSONObject(&quot;life&quot;); // JSONObject wind=realtime.getJSONObject(&quot;wind&quot;); // String time=realtime.getString(&quot;time&quot;); // JSONObject weather=realtime.getJSONObject(&quot;weather&quot;); // String date=realtime.getString(&quot;date&quot;); // dateStr=time+date; // weekStr=realtime.getString(&quot;week&quot;); // calendarStr=realtime.getString(&quot;moon&quot;); // windpowerStr=wind.getString(&quot;direct&quot;)+&quot; &quot;+wind.getString(&quot;power&quot;); // weatherStr=weather.getString(&quot;info&quot;); // temperatureStr=weather.getString(&quot;temperature&quot;); // JSONObject info=life.getJSONObject(&quot;info&quot;); // JSONArray kongtiao=info.getJSONArray(&quot;kongtiao&quot;); // JSONArray yundong=info.getJSONArray(&quot;yundong&quot;); // JSONArray ziwaixian=info.getJSONArray(&quot;ziwaixian&quot;); // ACStr=kongtiao.getString(0)+&quot; &quot;+kongtiao.getString(1); // sportStr=yundong.getString(0)+&quot; &quot;+yundong.getString(1); // lightStr=ziwaixian.getString(0)+&quot; &quot;+ziwaixian.getString(1);

讯享网 / * Gson数据解析 */ WheatherBean wheatherBean=new Gson().from<em>Json</em>(res,WheatherBean.class); String reason=wheatherBean.getReason(); if (reason.equals(&quot;参数不正确&quot;)){ handler.sendEmptyMessage(1); return; } WheatherBean.ResultBean resultBean=wheatherBean.getResult(); WheatherBean.ResultBean.RealtimeBean realtimeBean=resultBean.getRealtime(); WheatherBean.ResultBean.RealtimeBean.WindBean windBean=realtimeBean.getWind(); String time=realtimeBean.getTime(); WheatherBean.ResultBean.RealtimeBean.WeatherBean weatherBean=realtimeBean.getWeather(); String date=realtimeBean.getDate(); dateStr=time+date; weekStr=realtimeBean.getWeek(); calendarStr=realtimeBean.getMoon(); windpowerStr=windBean.getDirect()+&quot; &quot;+windBean.getPower(); temperatureStr=weatherBean.getTemperature(); weatherStr=weatherBean.getInfo(); WheatherBean.ResultBean.LifeBean lifeBean=resultBean.getLife(); WheatherBean.ResultBean.LifeBean.InfoBean infoBean=lifeBean.getInfo(); List&lt;String&gt; kongtiao=infoBean.getKongtiao(); List&lt;String&gt; yundong=infoBean.getYundong(); List&lt;String&gt; ziwaixian=infoBean.getZiwaixian(); ACStr=kongtiao.get(0)+&quot; &quot;+kongtiao.get(1); sportStr=yundong.get(0)+&quot; &quot;+yundong.get(1); lightStr=ziwaixian.get(0)+&quot; &quot;+ziwaixian.get(1); } 
小讯
上一篇 2025-06-14 20:35
下一篇 2025-04-24 13:26

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/142452.html