package com.weatherdemo.New;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.weatherdemo.until.Demo;
import com.weatherdemo.until.Weather;
public class JsonWeather {
public static Map<String, String> getJsonLogin(String str)
throws JSONException {
JSONObject obj = new JSONObject(str);
String resultcode = obj.getString("resultcode");
String reason = obj.getString("reason");
Map<String, String> map = new HashMap<String, String>();
map.put("resultcode", resultcode);
map.put("reason", reason);
return map;
}
/**
* 解析表单
*
*/
public static List<Map<String,String>> getWeather(String str) throws JSONException {
List<Weather> arr = new ArrayList<Weather>();
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
Map<String,String> map=null;
WeatherNew wNew=null;
JSONObject obj = new JSONObject(str);
String reason = obj.getString("reason");
String resultcode = obj.getString("resultcode");
int error_code = obj.getInt("error_code");
JSONObject jb = obj.getJSONObject("result");
JSONObject jb_sk=jb.getJSONObject("sk");/*当前实况天气*/
String temp = jb.getString("temp");/*当前温度*/
String wind_direction = jb_sk.getString("wind_direction");/*当前风向*/
String wind_strength = jb_sk.getString("wind_strength");/*当前风力*/
String humidity = jb_sk.getString("humidity"); /*当前湿度*/
String time = jb_sk.getString("time");/*更新时间*/
JSONObject jb_today=jb.getJSONObject("today");
String city = jb_today.getString("city");
String date_y = jb_today.getString("date_y");
String week = jb_today.getString("week");
String temperature = jb_today.getString("temperature");/*今日温度*/
String weather = jb_today.getString("weather");/*今日天气*/
JSONObject jb_today_weather_id=jb_today.getJSONObject("weather_id");
String fa = jb_today_weather_id.getString("fa");/*天气标识00:晴*/
String fb = jb_today_weather_id.getString("fb");/*天气标识53:霾 如果fa不等于fb,说明是组合天气*/
String wind = jb_today.getString("wind");
String dressing_index = jb_today.getString("dressing_index");/*穿衣指数*/
String dressing_advice = jb_today.getString("dressing_advice");/*穿衣建议*/
String uv_index = jb_today.getString("uv_index"); /*紫外线强度*/
String comfort_index = jb_today.getString("comfort_index");/*舒适度指数*/
String wash_index = jb_today.getString("wash_index");/*洗车指数*/
String travel_index = jb_today.getString("travel_index");/*旅游指数*/
String exercise_index = jb_today.getString("exercise_index");/*晨练指数*/
String drying_index = jb_today.getString("drying_index");/*干燥指数*/
JSONArray ja=jb.getJSONArray("future"); /*未来几天天气*/
for(int i=0;i<ja.length();i++){
JSONObject jb_future=ja.getJSONObject(i);
String temperature_future = jb_future.getString("temperature");/*今日温度*/
String weather_future = jb_future.getString("weather");/*今日天气*/
JSONObject jb_future_weather_id=jb_future.getJSONObject("weather_id");
String fa_future = jb_future_weather_id.getString("fa");/*天气标识00:晴*/
String fb_future = jb_future_weather_id.getString("fb");/*天气标识53:霾 如果fa不等于fb,说明是组合天气*/
String wind_future = jb_today.getString("wind");
String date_future = jb_today.getString("date");
String week_future = jb_today.getString("week");
map=new HashMap<String, String>();
map.put("temperature_future",temperature_future );
map.put("weather_future",weather_future );
map.put("fa_future",fa_future );
map.put("fb_future",fb_future );
map.put("wind_future",wind_future );
map.put("date_future",date_future );
map.put("week_future",week_future );
}
list.add(map);
// demo=new Demo(weatherid, weather, temp1, temp2, sh, eh, date, sfdate, efdate);
// demo=new Demo();
// demo.setWeatherid(weatherid);
// demo.setDate(efdate);
// demo.setEfdate(efdate);
// demo.setEh(eh);
// demo.setSfdate(sfdate);
// demo.setSh(sh);
// demo.setTemp1(temp1);
// demo.setTemp2(temp2);
// demo.setWeather(weather);
return list;
}
}