L'exemple de cet article indique la façon dont Java appelle l'API China Weather Network pour obtenir des informations sur les prévisions météorologiques. Partagez-le pour tout le monde pour votre référence. La méthode de mise en œuvre spécifique est la suivante:
// Prenez Bingcheng Harbin comme exemple pour appeler les informations météorologiques via l'API météorologique chinoise. ResponseHandler <string> ResponseHandler = new BasicResponseHandler (); String ResponseBody = httpclient.Exec ute (httget, réponse); ; J = JSO.get ("temp1"). Conditions // String j_weather = jso.get ("Weather1"). // // Wind Direction et Wind // String J_Wind = JSO.get ("Wind1"). // info.append ("aujourd'hui:"). /// n "); // info.append (" "demain:"). / n "); //} string updtime = jso.get (" "fchh"). // chaîne de température j = jso.get ("temp1"). get ("weather1" ("weather1" ") .getAsstring (); // aujourd'hui string m_weather = jso.get (" weather2 "). getasstring (); // demain // direction du vent force de force j_wind = jso.get (Wind1 "). ") .Appnd (j_weather).) .Appnd (j_wind) .appnd (" / n "); info.append (" "demain:"). appnd ("") .Aptend (m_wind) .Appnd ("/ n");} else {// 18 // chaîne de température temp1 = jso.get ("temp1"). JSO.get ("temp2"). 0]; String m = temp2 "). GetAsstring (); string weather2 = jso.get (" weather2 "). GetAsstring (); string weather3 = jso.get (" weather3 "). Ather =" "; string j_weather_part1 =" "; string j_weather_part2 =" "";;; (Weather2.Indexof ("Turn")> 0) {// j_weather_part2 = weather2.split ("tour") [0];} else {j_weather_part2 = weather2;} i f (j_weather_part1.equalsignorecase (j_weather_part2)) {j_weather = J_Weather_Part1; .Indexof ("tour")> 0) {// Il y a m_weather_part1 = weather2.split ("tour") [1];} else {m_weather_part1 = weather2;} if (Weather3.Indexof ("tour (" Turn to " )> 0) {// Il y a m_weather_part2 = weather3.split ("tour") [0];} else {m_weather_part2 = weather3;} if (m_weather_part1.equalsignorecase (m_weather_part2)) {m_weather = m_weather_part1; {m_weather = m_weather_part1 + "Turn" + m_weather_part2; / demain info.APPEND ("Aujourd'hui:"). ) ;; ("" Demain: "). }}}}}}}}}}}}}}}}}}}}}}} catch (exception e) {} return info.tostring ();}
On espère que cet article est utile à la conception du programme Java de tous.