内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

java天氣預(yù)報(bào)完整代碼 java天氣預(yù)報(bào)完整代碼下載

java web service實(shí)現(xiàn)天氣預(yù)報(bào)功能

前臺(tái)js界面代碼:

10年的珠暉網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整珠暉建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“珠暉網(wǎng)站設(shè)計(jì)”,“珠暉網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

//省份

function?LoadProvince()?{

$.ajax({

type:?"POST",

url:?"ashx/weatherHandler.ashx",

data:?"option=province",

success:?function?(result)?{

$(".sel-province?option").remove();

var?arry?=?result.split('|');

var?obj?=?null;

for?(var?i?=?0;?i??arry.length;?i++)?{

if?(arry[i]?!=?null??arry[i]?!=?"")?{

obj?=?arry[i].split(',');

$(".sel-province").append("option?value='"?+?obj[1]?+?"'"?+?obj[0]?+?"/option");

}

}

$(".sel-province").find("option[text='北京']").attr("selected",?"selected");

},

error:?function?(errorMsg)?{

$(".result-table?tr").remove();

$(".result-table").append("trtd省份請(qǐng)求出現(xiàn)錯(cuò)誤,請(qǐng)您稍后重試。。。/td/tr");

}

});

}

//城市

function?LoadCity(provinceid)?{???

$.ajax({

type:?"POST",

url:?"ashx/weatherHandler.ashx",

data:?"provinceid="?+?provinceid?+?"option=city",

success:?function?(result)?{

$(".sel-city?option").remove();

var?arry?=?result.split('|');

var?obj?=?null;

for?(var?i?=?0;?i??arry.length;?i++)?{

if?(arry[i]?!=?null??arry[i]?!=?"")?{

obj?=?arry[i].split(',');

$(".sel-city").append("option?value='"?+?obj[1]?+?"'"?+?obj[0]?+?"/option");

}

}

},

error:?function?(errorMsg)?{

$(".result-table?tr").remove();

$(".result-table").append("trtd城市請(qǐng)求出現(xiàn)錯(cuò)誤,請(qǐng)您稍后重試。。。/td/tr");

}

});

}

//加載天氣

function?GetWeather(cityid)?{

$.ajax({

type:?"POST",

url:?"ashx/weatherHandler.ashx",

data:?"cityid="?+?cityid?+?"option=weather",

success:?function?(result)?{

$(".result-table?tr").remove();

var?arry?=?result.split('|');

var?obj?=?null;

for?(var?i?=?0;?i??arry.length;?i++)?{

if?(arry[i]?!=?null??arry[i]?!=?"")?{

if?(arry[i].indexOf(".gif")??0)?{

$(".result-table").append("trtdimage?src='images/"?+?arry[i]?+?"'//td/tr");

}

else?{

$(".result-table").append("trtd"?+?arry[i]?+?"/td/tr");

}

}

}

},

error:?function?(errorMsg)?{

$(".result-table?tr").remove();

$(".result-table").append("trtd天氣數(shù)據(jù)請(qǐng)求出現(xiàn)錯(cuò)誤,請(qǐng)您稍后重試。。。/td/tr");

}

});

}

html代碼:

body

form?id="form1"?runat="server"

div?class="head-div"

table

tr

td

select?class="sel-province?sel"

/select

/td

td

select?class="sel-city?sel"

/select

/td

td

input?type="button"?class="btn-search"?value="查詢"?/

/td

/tr

/table

/div

div?class="result-div"

table?class="result-table"

/table

/div

/form

/body

由于js不支持跨域,直接ajax+ashx一般處理程序(在里面調(diào)用天氣接口)。一般處理程序代碼如下:

using?System.Web;

using?System;

using?System.Collections.Generic;

using?System.Linq;

using?System.Web;

using?System.Text;

namespace?WeatherTest.ashx

{

///?summary

///?weatherHandler?的摘要說(shuō)明

///?/summary

public?class?weatherHandler?:?IHttpHandler

{

WeatherWsClient.WeatherWSSoapClient?client?=?new?WeatherWsClient.WeatherWSSoapClient();

public?void?ProcessRequest(HttpContext?context)

{

context.Response.ContentType?=?"text/plain";

string[]?result?=?null;

string?option?=?context.Request.Form["option"];

switch?(option)

{

case?"province":

result?=?GetProvinces();

break;

case?"city":

result?=?GetCitys(context.Request.Form["provinceid"]);

break;

case?"weather":

result?=?GetWeather(context.Request.Form["cityid"],?null);

break;

}

string?str?=?ConvertToString(result,?option);

context.Response.Write(str);

}

///?summary

///?數(shù)組轉(zhuǎn)字符串

///?/summary

///?param?name="result"/param

///?param?name="option"/param

///?returns/returns

private?string?ConvertToString(string[]?result,?string?option)

{

StringBuilder?sb?=?new?StringBuilder();

foreach?(string?item?in?result)

{

sb.Append(item+"|");

}

return?sb.ToString();

}

///?summary

///?省份

///?/summary

///?returns/returns

private?string[]?GetProvinces()

{

return?client.getRegionProvince();

}

///?summary

///?城市

///?/summary

///?param?name="provinceid"/param

///?returns/returns

private?string[]?GetCitys(string?provinceid)

{

return?client.getSupportCityString(provinceid);

}

///?summary

///?天氣數(shù)據(jù)

///?/summary

///?param?name="cityid"/param

///?param?name="userid"/param

///?returns/returns

private?string[]?GetWeather(string?cityid,?string?userid)

{

return?client.getWeather(cityid,?userid);

}

public?bool?IsReusable

{

get

{

return?false;

}

}

}

}

大家好 我剛才在寫(xiě)java天氣預(yù)報(bào) 我用json解析的數(shù)據(jù)怎樣放到j(luò)ava界面?

可以在JFrame中添加幾個(gè)Label控件或其他文本控件用來(lái)展示解析出來(lái)的結(jié)果

java調(diào)天氣預(yù)報(bào)

①取出地址中的返回值(getWeatherReader方法)

②解析json格式的字符串

③形成你要展示的天氣預(yù)報(bào)效果

public static String getWeatherReader() {//取得接口字符串

String currentLine = "";

String strReturn = "";

URL url = null;

HttpURLConnection conn = null;

InputStream in = null;

BufferedReader buff = null;

try {

url = new URL("");

System.out.println(url.toURI());

//打開(kāi)地址鏈接

conn = (HttpURLConnection)url.openConnection();

conn.connect();

//接收數(shù)據(jù)

in = conn.getInputStream();

//如有亂碼注意編碼方式,如:UTF-8

buff = new BufferedReader(new InputStreamReader(in, "gb2312"));

while((currentLine = buff.readLine()) != null) {

strReturn += currentLine;

}

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

in.close();

buff.close();

} catch (IOException e) {

return "8EF0000";

}

}

return strReturn;

}

求Android天氣預(yù)報(bào)的開(kāi)發(fā)源代碼

package com.nrzc.weatherstation;

import android.content.Context;

import android.hardware.Sensor;

import android.hardware.SensorEvent;

import android.hardware.SensorEventListener;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.widget.TextView;

import java.util.Timer;

import java.util.TimerTask;

/**

* 環(huán)境傳感器

* 氣象站

*/

public class MainActivity extends AppCompatActivity {

private SensorManager sensorManager;

private TextView temperatureTextView;

private TextView pressureTextView;

private TextView lightTextView;

private float currentTemperature=Float.NaN;

private float currentPressure=Float.NaN;

private float currentLight=Float.NaN;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

init();

Timer updateTimer=new Timer("weatherUpdate");

updateTimer.scheduleAtFixedRate(new TimerTask() {

@Override

public void run() {

updateGUI();

}

},0,1000);

}

private void init(){

temperatureTextView=(TextView)findViewById(R.id.temperature);

pressureTextView=(TextView)findViewById(R.id.pressure);

lightTextView=(TextView)findViewById(R.id.light);

sensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);

}

private final SensorEventListener tempSensorEventListener=new SensorEventListener() {

@Override

public void onSensorChanged(SensorEvent event) {

currentTemperature=event.values[0];

}

@Override

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

};

private final SensorEventListener pressureSensorEventListener=new SensorEventListener() {

@Override

public void onSensorChanged(SensorEvent event) {

currentPressure=event.values[0];

}

@Override

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

};

private final SensorEventListener lightSensorEventListener=new SensorEventListener() {

@Override

public void onSensorChanged(SensorEvent event) {

currentLight=event.values[0];

}

@Override

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

};

@Override

protected void onResume() {

super.onResume();

Sensor lightSensor=sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

if (lightSensor!=null)

sensorManager.registerListener(lightSensorEventListener,

lightSensor,

SensorManager.SENSOR_DELAY_NORMAL);

else

lightTextView.setText("Light Sensor Unavailable");

Sensor pressureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);

if (pressureSensor!=null)

sensorManager.registerListener(pressureSensorEventListener,

pressureSensor,SensorManager.SENSOR_DELAY_NORMAL);

else

pressureTextView.setText("Barometer Unavailable");

Sensor temperatureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);

if (temperatureSensor!=null)

sensorManager.registerListener(tempSensorEventListener,

temperatureSensor,

SensorManager.SENSOR_DELAY_NORMAL);

else

temperatureTextView.setText("Thermometer Unavailable");

}

@Override

protected void onPause() {

sensorManager.unregisterListener(pressureSensorEventListener);

sensorManager.unregisterListener(tempSensorEventListener);

sensorManager.unregisterListener(lightSensorEventListener);

super.onPause();

}

private void updateGUI(){

runOnUiThread(new Runnable() {

@Override

public void run() {

if(!Float.isNaN(currentPressure)){

pressureTextView.setText(currentPressure+"hPa");

pressureTextView.invalidate();

}

if (!Float.isNaN(currentLight)){

String lightStr="Sunny";

if (currentLight=SensorManager.LIGHT_CLOUDY)

lightStr="night";

else if (currentLight=SensorManager.LIGHT_OVERCAST)

lightStr="Cloudy";

else if (currentLight=SensorManager.LIGHT_SUNLIGHT)

lightStr="Overcast";

lightTextView.setText(lightStr);

lightTextView.invalidate();

}

if (!Float.isNaN(currentTemperature)){

temperatureTextView.setText(currentTemperature+"C");

temperatureTextView.invalidate();

}

}

});

}

}

java調(diào)用天氣預(yù)報(bào)api怎么寫(xiě)

//通過(guò)中國(guó)天氣api調(diào)用

private String getWeatherInfo2(){

StringBuilder info = new StringBuilder();

try {

DefaultHttpClient httpclient = new DefaultHttpClient();

HttpGet httget = new HttpGet("");

ResponseHandlerString responseHandler = new BasicResponseHandler();

String responseBody = httpclient.execute(httget, responseHandler);

System.out.println(responseBody);

JsonParser jp = new JsonParser();

JsonElement jse = jp.parse(responseBody);

JsonObject jso = jse.getAsJsonObject().get("weatherinfo").getAsJsonObject();

// String updTime = jso.get("fchh").getAsString();

// if(updTime != null){

// //溫度

// String j = jso.get("temp1").getAsString();//今天

// String m = jso.get("temp2").getAsString();//明天

// //天氣情況

// String j_weather = jso.get("weather1").getAsString();//今天

// String m_weather = jso.get("weather2").getAsString();//明天

// //風(fēng)向風(fēng)力

// String j_wind = jso.get("wind1").getAsString();//今天

// String m_wind = jso.get("wind2").getAsString();//明天

// info.append("今天:").append(j).append(" ").append(j_weather).append(" ").append(j_wind).append("\n");

// info.append("明天:").append(m).append(" ").append(m_weather).append(" ").append(m_wind).append("\n");

// }

String updTime = jso.get("fchh").getAsString();

if(updTime != null){

if(!updTime.trim().equals("18")){

//溫度

String j = jso.get("temp1").getAsString();//今天

String m = jso.get("temp2").getAsString();//明天

//天氣情況

String j_weather = jso.get("weather1").getAsString();//今天

String m_weather = jso.get("weather2").getAsString();//明天

//風(fēng)向風(fēng)力

String j_wind = jso.get("wind1").getAsString();//今天

String m_wind = jso.get("wind2").getAsString();//明天

info.append("今天:").append(j).append(" ").append(j_weather).append(" ").append(j_wind).append("\n");

info.append("明天:").append(m).append(" ").append(m_weather).append(" ").append(m_wind).append("\n");

}else{

//18

//溫度

String temp1 = jso.get("temp1").getAsString();//今天

String temp2 = jso.get("temp2").getAsString();//今天

String temp3 = jso.get("temp3").getAsString();//今天

String j = temp1.split("~")[1] + "~" + temp2.split("~")[0];

String m = temp2.split("~")[1] + "~" + temp3.split("~")[0];//明天

//天氣情況

String weather1 = jso.get("weather1").getAsString();

String weather2 = jso.get("weather2").getAsString();

String weather3 = jso.get("weather3").getAsString();

String j_weather = "";

String j_weather_part1 = "";

String j_weather_part2 = "";

//判斷是否有轉(zhuǎn)

if(weather1.indexOf("轉(zhuǎn)") 0){

//有

j_weather_part1 = weather1.split("轉(zhuǎn)")[1];

}else{

j_weather_part1 = weather1;

}

if(weather2.indexOf("轉(zhuǎn)") 0){

//有

j_weather_part2 = weather2.split("轉(zhuǎn)")[0];

}else{

j_weather_part2 = weather2;

}

if(j_weather_part1.equalsIgnoreCase(j_weather_part2)){

j_weather = j_weather_part1;//今天

}else{

j_weather = j_weather_part1 + "轉(zhuǎn)" + j_weather_part2;//今天

}

String m_weather = "";

String m_weather_part1 = "";

String m_weather_part2 = "";

//判斷是否有轉(zhuǎn)

if(weather2.indexOf("轉(zhuǎn)") 0){

//有

m_weather_part1 = weather2.split("轉(zhuǎn)")[1];

}else{

m_weather_part1 = weather2;

}

if(weather3.indexOf("轉(zhuǎn)") 0){

//有

m_weather_part2 = weather3.split("轉(zhuǎn)")[0];

}else{

m_weather_part2 = weather3;

}

if(m_weather_part1.equalsIgnoreCase(m_weather_part2)){

m_weather = m_weather_part1;//今天

}else{

m_weather = m_weather_part1 + "轉(zhuǎn)" + m_weather_part2;//明天

}

//風(fēng)向風(fēng)力

String j_wind = jso.get("wind2").getAsString();//今天

String m_wind = jso.get("wind3").getAsString();//明天

info.append("今天:").append(j).append(" ").append(j_weather).append(" ").append(j_wind).append("\n");

info.append("明天:").append(m).append(" ").append(m_weather).append(" ").append(m_wind).append("\n");

}

}

} catch (Exception e) {

}

return info.toString();

}

當(dāng)前名稱:java天氣預(yù)報(bào)完整代碼 java天氣預(yù)報(bào)完整代碼下載
網(wǎng)站網(wǎng)址:http://www.rwnh.cn/article42/hhgeec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、動(dòng)態(tài)網(wǎng)站、全網(wǎng)營(yíng)銷推廣、網(wǎng)站策劃、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)
长汀县| 广西| 达孜县| 土默特右旗| 元谋县| 江北区| 江源县| 静海县| 梅河口市| 龙口市| 朝阳市| 上高县| 杭州市| 安溪县| 荆门市| 霍州市| 平陆县| 保德县| 柳州市| 石河子市| 浙江省| 潜江市| 喀什市| 莆田市| 蓬溪县| 霞浦县| 泸溪县| 玛曲县| 郴州市| 临潭县| 清远市| 蕲春县| 岚皋县| 将乐县| 平谷区| 信阳市| 信阳市| 荔浦县| 新安县| 通山县| 白玉县|