WeatherdemoNew

Json:

package com.weatherdemo.until;

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 android.util.Log;


public class JsonActivityNew {
 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<Weather> getMenuDemoh(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;
  Weather wDemo = null;
  Demo demo=null;
  JSONObject obj = new JSONObject(str);
  String reason = obj.getString("reason");
  String resultcode = obj.getString("resultcode");
  int error_code = obj.getInt("error_code");


  JSONArray ja = obj.getJSONArray("result");
  for (int i = 0; i < ja.length(); i++) {
   JSONObject jb = ja.getJSONObject(i);
   
   String weatherid = jb.getString("weatherid");
   String weather = jb.getString("weather");
   String temp1 = jb.getString("temp1");
   String temp2 = jb.getString("temp2");
   String sh = jb.getString("sh");
   String eh = jb.getString("eh");
   String date = jb.getString("date");
   String sfdate = jb.getString("sfdate");
   String efdate = jb.getString("efdate");
   
   map=new HashMap<String, String>();
   map.put("weatherid",weatherid );
   map.put("weather",weather );
   map.put("temp1",temp1 );
   map.put("temp2",temp2 );
   map.put("sh",sh );
   map.put("eh",eh );
   map.put("date",date );
   map.put("sfdate",sfdate );
   map.put("efdate",efdate );
   
   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);
   
   
  }
//  System.out.println("list-----"+list);
  System.out.println("示范-----"+list.get(0).get("weather"));
  wDemo=new Weather(resultcode, reason, demo, error_code);
  
  arr.add(wDemo);
  
//  System.out.println("arr---"+arr);
  return arr;
 }
}

 

package com.weatherdemo;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import com.weatherdemo.until.HttpUtil;
import com.weatherdemo.until.JsonActivityNew;
import com.weatherdemo.until.Weather;

public class WeatherDemoLogic {
 /**
  * 获取网上菜单表内容
  */
 public List<Weather> WeatherDemo(String cityname) throws ClientProtocolException, IOException,
   JSONException {
 
  Map<String, String> map = new HashMap<String, String>();
  map.put("key", "c1bb4fcbf131db6aa9b451d52b09cbae");
  map.put("dtype", "json");
  map.put("cityname", cityname);
  
  String str = HttpUtil.getRequest("forecast3h", map);
  
//System.out.println("str---"+str);
  
  List<Weather> requst = JsonActivityNew.getMenuDemoh(str);
  
  return requst;
}
}

转载于:https://my.oschina.net/u/1994482/blog/418667

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值