1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 温度历史数据php 历史天气API接口_数据接口 - 极速数据

温度历史数据php 历史天气API接口_数据接口 - 极速数据

时间:2018-11-10 13:03:55

相关推荐

温度历史数据php 历史天气API接口_数据接口 - 极速数据

package api.jisuapi.weather;

import api.util.HttpUtil;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

public class City {

public static final String APPKEY = "your_appkey_here";// 你的appkey

public static final String URL = "/weather2/city";

public static void Get() {

String result = null;

String url = URL + "?appkey=" + APPKEY;

try {

result = HttpUtil.sendGet(url, "utf-8");

JSONObject json = JSONObject.fromObject(result);

if (json.getInt("status") != 0) {

System.out.println(json.getString("msg"));

} else {

JSONArray resultarr = json.optJSONArray("result");

for (int i = 0; i < resultarr.size(); i++) {

JSONObject obj = (JSONObject) resultarr.opt(i);

String cityid = obj.getString("cityid");

String parentid = obj.getString("parentid");

String citycode = obj.getString("citycode");

String city = obj.getString("city");

System.out.println(cityid + " " + parentid + " " + citycode + " " + city);

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。