var url="https://www.weatherol.cn/api/home/getCurrAnd15dAnd24h?cityid=101010600";
window.java_obj.showLog("data url:"+url);
var xhr = new XMLHttpRequest();

xhr.onerror = function(error){
    window.java_obj.showLog(error.toString());
};
xhr.ontimeout = function () {
    window.java_obj.showLog("timeout");
};
xhr.onreadystatechange = function () {
   window.java_obj.showLog(this.readyState+","+this.status);
   if(this.readyState==4&&this.status==200){
      window.java_obj.showLog("result,"+this.response);
                   var json=JSON.parse(this.response);
                   var current=json.data.current.current;
                   window.java_obj.showLog("start2");

                    var weatherNowBean={
                        cloud:"",
                        text:current.weather,
                        dew:"",
                        humidity:current.humidity,
                        icon:current.weatherPic,
                        feelIsLike:current.feelstemperature,
                        obsTime:current.reporttime,
                        precip:"",
                        pressure:current.airpressure,
                        temp:current.temperature,
                        vis:current.visibility,
                        wind360:"",
                        windDir:current.winddir,
                        windScale:current.windpower,
                        windSpeed:""
                    };
                    window.java_obj.setData(JSON.stringify(weatherNowBean),"NowBaseBean");

                 var hourlys=json.data.forecast24h;
                 var arr=[];
                 var date=new Date();
                 var month=date.getUTCMonth()+1;
                 var dateStr=date.getUTCFullYear()+"-"+(month<9?"0"+month:month)+"-"+date.getUTCDate();
                 for(var i=0;i<hourlys.length;i++){
                     var item=hourlys[i];
                     var hourlyBean={fxTime:dateStr+"T"+item.forecasttime+"+08:00",temp:item.temperature.replace("℃",""),icon:item.weatherPic,text:item.weather,wind360:item.windDirectionDegree,windDir:item.windDir,windScale:item.windPower};
                     arr.push(hourlyBean);
                 }
                 window.java_obj.setData(JSON.stringify(arr),"List<HourlyBean>");

                 arr=[];
                 var dailyBeans=json.data.forecast15d;
                 var year=new Date().getUTCFullYear();
                 for(var i=0;i<dailyBeans.length;i++){
                     var item=dailyBeans[i];
                     var dailyBean={
                         fxDate:year+"-"+item.forecasttime.replace("/","-"),
                         sunrise:"",
                         sunset:"",
                         moonRise:"",
                         moonSet:"",
                         moonPhase:"",
                         tempMax:item.temperature_am,
                         tempMin:item.temperature_pm,
                         iconDay:item.weather_am_pic,
                         textDay:item.weather_am,
                         iconNight:item.weather_pm_pic,
                         textNight:item.weather_pm,
                         wind360Day:"",
                         windDirDay:item.winddir_am,
                         windScaleDay:item.windpower_am,
                         windSpeedDay:"",
                         wind360Night:"",
                         windDirNight:item.winddir_pm,
                         windScaleNight:item.windpower_pm,
                         windSpeedNight:"",
                         humidity:"",
                         precip:"",
                         pressure:"",
                         vis:"",
                         cloud:"",
                         uvIndex:"",
                     };
                     arr.push(dailyBean);
                 }
                 window.java_obj.setData(JSON.stringify(arr),"List<DailyBean>");

   }
};
xhr.open('GET', url, true);
xhr.send(null);

