ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:18.79KB ,
资源ID:9732802      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9732802.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(解析JSON数据.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

解析JSON数据.docx

1、解析JSON数据生活指南原始JSON数据: results: location: id: WHX38U36B3BU, name: 大理, country: CN, path: 大理,大理,云南,中国, timezone: Asia/Shanghai, timezone_offset: 08:00 , suggestion: car_washing: brief: 不宜, details: 不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。 , dressing: brief: 舒适, details: 建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长

2、袖衬衫、马甲和长裤。 , flu: brief: 少发, details: 各项气象条件适宜,无明显降温过程,发生感冒机率较低。 , sport: brief: 较不宜, details: 有降水,推荐您在室内进行健身休闲运动;若坚持户外运动,须注意保暖并携带雨具。 , travel: brief: 适宜, details: 有降水,温度适宜,在细雨中游玩别有一番情调,可不要错过机会呦!但记得出门要携带雨具。 , uv: brief: 弱, details: 紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA 的防晒护肤品。 , last_update: 2016-06-10T16:4

3、0:10 08:00 实时天气情况原始JSON数据: results: location: id: WHX38U36B3BU, name: 大理, country: CN, path: 大理,大理,云南,中国, timezone: Asia/Shanghai, timezone_offset: 08:00 , now: text: 阵雨, code: 10, temperature: 19 , last_update: 2016-06-10T16:25:00 08:00 未来几天天气预报原始JSON数据: results: location: id: WHX38U36B3BU, name: 大

4、理, country: CN, path: 大理,大理,云南,中国, timezone: Asia/Shanghai, timezone_offset: 08:00 , daily: date: 2016-06-10, text_day: 阵雨, code_day: 10, text_night: 阵雨, code_night: 10, high: 24, low: 16, precip: , wind_direction: 无持续风向, wind_direction_degree: , wind_speed: 10, wind_scale: 2 , date: 2016-06-11, tex

5、t_day: 阵雨, code_day: 10, text_night: 小雨, code_night: 13, high: 22, low: 17, precip: 80, wind_direction: 无持续风向, wind_direction_degree: , wind_speed: 10, wind_scale: 2 , date: 2016-06-12, text_day: 中雨, code_day: 14, text_night: 小雨, code_night: 13, high: 24, low: 17, precip: 90, wind_direction: 无持续风向,

6、wind_direction_degree: , wind_speed: 10, wind_scale: 2 , last_update: 2016-06-10T11:00:00 08:00 解析JSON:package com.lastexam.weatherforecast;import java.util.ArrayList;import java.util.Scanner;import net.sf.json.JSONArray;import net.sf.json.JSONObject;public class ParseJSON /* public static void main

7、(String args) Scanner in=new Scanner(System.in); System.out.println(请输入数据:); String string=in.next(); System.out.println(ParseResult(string); Location location=new Location(); location=ParseLocation(ParseResult(string); System.out.println(location.toString(); /实时天气情况解析完毕 RealNow now=new RealNow(); n

8、ow=ParseNow(ParseResult(string); System.out.println(now.toString(); /天气预报解析完毕 WeatherDaily daily=ParseDaily(ParseResult(string); for(int i=0;idaily.length;i ) System.out.println(dailyi.toString(); /suggestion解析完毕 SuggestionCarWashing carWashing=new SuggestionCarWashing(); carWashing=ParseCarWashing(

9、ParseResult(string); System.out.println(carWashing.toString(); SuggestionDressing dressing=new SuggestionDressing(); dressing=ParseDressing(ParseResult(string); System.out.println(dressing.toString(); SuggestionFlu flu=new SuggestionFlu(); flu=ParseFlu(ParseResult(string); System.out.println(flu.toS

10、tring(); SuggestionSport sport=new SuggestionSport(); sport=ParseSport(ParseResult(string); System.out.println(sport.toString(); SuggestionTravel travel=new SuggestionTravel(); travel=ParseTravel(ParseResult(string); System.out.println(travel.toString(); SuggestionUv uv=new SuggestionUv(); uv=ParseU

11、v(ParseResult(string); System.out.println(uv.toString(); System.out.println(ParseUpdateTime(ParseResult(string); */ /将原始的JSON数据解析之后返回(主要是提取result中的内容) public String ParseResult(String originalJSON) JSONObject resultsJSONObject=JSONObject.fromObject(originalJSON); JSONArray resultsJSONArray=resultsJS

12、ONObject.getJSONArray(results); return resultsJSONArray.getJSONObject(0).toString(); /提取location中的内容,并且将提取出来的内容放到Location对象中并返回 public Location ParseLocation(String resultJSON) Location location=new Location(); JSONObject locationJSONObjectOriginal=JSONObject.fromObject(resultJSON); String locationS

13、tring=locationJSONObjectOriginal.getString(location); JSONObject locationJSONObject=JSONObject.fromObject(locationString); location.setId(locationJSONObject.getString(id); location.setName(locationJSONObject.getString(name); location.setContry(locationJSONObject.getString(country); location.setPath(

14、locationJSONObject.getString(path); location.setTimezone(locationJSONObject.getString(timezone); location.setTimezone_offset(locationJSONObject.getString(timezone_offset); return location; /提取实时天气情况中的now的内容,并将提取出来的内容放入到RealNow的对象里面并返回 public RealNow ParseNow(String resultJSON) RealNow now=new RealNo

15、w(); JSONObject nowJSONObjectOriginal=JSONObject.fromObject(resultJSON); String nowString=nowJSONObjectOriginal.getString(now); JSONObject nowJSONObject=JSONObject.fromObject(nowString); now.setText(nowJSONObject.getString(text); now.setCode(nowJSONObject.getString(code); now.setTemperature(nowJSONO

16、bject.getString(temperature); return now; /提取天气预报中的daily的内容,并将提取出来的内容放入到WeatherDaily的对象里面并返回 public WeatherDaily ParseDaily(String resultJSON) WeatherDaily daily=new WeatherDaily3; daily0=new WeatherDaily(); daily1=new WeatherDaily(); daily2=new WeatherDaily(); JSONObject dailyJSONObjectOriginal=JSO

17、NObject.fromObject(resultJSON); JSONArray dailyJsonArray=dailyJSONObjectOriginal.getJSONArray(daily); for(int i=0;idailyJsonArray.size();i ) String dailyString=dailyJsonArray.get(i).toString(); JSONObject dailyJSONObject=JSONObject.fromObject(dailyString); dailyi.setDate(dailyJSONObject.getString(da

18、te); dailyi.setText_day(dailyJSONObject.getString(text_day); dailyi.setCode_day(dailyJSONObject.getString(code_day); dailyi.setText_night(dailyJSONObject.getString(text_night); dailyi.setCode_night(dailyJSONObject.getString(code_night); dailyi.setHigh(dailyJSONObject.getString(high); dailyi.setLow(d

19、ailyJSONObject.getString(low); dailyi.setPrecip(dailyJSONObject.getString(precip); dailyi.setWind_direction(dailyJSONObject.getString(wind_direction); dailyi.setWind_direction_degree(dailyJSONObject.getString(wind_direction_degree); dailyi.setWind_speed(dailyJSONObject.getString(wind_speed); dailyi.

20、setWind_scale(dailyJSONObject.getString(wind_scale); return daily; /提取suggestion中的car_washing的内容,并且将内容放入SuggestionCarWashing的对象之中,并返回 public SuggestionCarWashing ParseCarWashing(String resultJSON) SuggestionCarWashing carWashing=new SuggestionCarWashing(); JSONObject suggestionJSONObjectOriginal=JSO

21、NObject.fromObject(resultJSON); String suggestionString=suggestionJSONObjectOriginal.getString(suggestion); JSONObject carWashingJSONObjectOriginal=JSONObject.fromObject(suggestionString); String carWashingString=carWashingJSONObjectOriginal.getString(car_washing); JSONObject carWashingJSONObject=JS

22、ONObject.fromObject(carWashingString); carWashing.setBrief(carWashingJSONObject.getString(brief); carWashing.setDetails(carWashingJSONObject.getString(details); return carWashing; /提取suggestion中的dressing的内容,并且将内容放入SuggestionDressing的对象之中,并返回 public SuggestionDressing ParseDressing(String resultJSON)

23、 SuggestionDressing dressing=new SuggestionDressing(); JSONObject suggestionJSONObjectOriginal=JSONObject.fromObject(resultJSON); String suggestionString=suggestionJSONObjectOriginal.getString(suggestion); JSONObject dressingJSONObjectOriginal=JSONObject.fromObject(suggestionString); String dressing

24、String=dressingJSONObjectOriginal.getString(dressing); JSONObject dressingJSONObject=JSONObject.fromObject(dressingString); dressing.setBrief(dressingJSONObject.getString(brief); dressing.setDetails(dressingJSONObject.getString(details); return dressing; /提取suggestion中的flu的内容,并且将内容放入SuggestionFlu的对象

25、之中,并返回 public SuggestionFlu ParseFlu(String resultJSON) SuggestionFlu flu=new SuggestionFlu(); JSONObject suggestionJSONObjectOriginal=JSONObject.fromObject(resultJSON); String suggestionString=suggestionJSONObjectOriginal.getString(suggestion); JSONObject fluJSONObjectOriginal=JSONObject.fromObject

26、(suggestionString); String fluString=fluJSONObjectOriginal.getString(flu); JSONObject fluJSONObject=JSONObject.fromObject(fluString); flu.setBrief(fluJSONObject.getString(brief); flu.setDetails(fluJSONObject.getString(details); return flu; /提取suggestion中的sport的内容,并且将内容放入SuggestionSport的对象之中,并返回 publ

27、ic SuggestionSport ParseSport(String resultJSON) SuggestionSport sport=new SuggestionSport(); JSONObject suggestionJSONObjectOriginal=JSONObject.fromObject(resultJSON); String suggestionString=suggestionJSONObjectOriginal.getString(suggestion); JSONObject sportJSONObjectOriginal=JSONObject.fromObjec

28、t(suggestionString); String sportString=sportJSONObjectOriginal.getString(sport); JSONObject sportJSONObject=JSONObject.fromObject(sportString); sport.setBrief(sportJSONObject.getString(brief); sport.setDetails(sportJSONObject.getString(details); return sport; /提取suggestion中的travel的内容,并且将内容放入SuggestionTravel的对象之中,并返回 public Sugg

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1