O exemplo deste artigo informa como Java chama a API da China Weather Network para obter informações sobre previsão do tempo. Compartilhe para todos para sua referência. O método de implementação específico é o seguinte:
// Tome Bingcheng Harbin como um exemplo para chamar as informações climáticas através da API climática chinesa. ResponseHandler <string> ResponseHandler = New BasicResponseHandler (); JsonObject JSO = JSE.getasjsonObject (). J = JSO.get ("Temp1"). Condições // String j_weather = JSO.get ("Weather1"). // // Wind Direction e Wind // String j_wind = JSO.get ("Wind1") // info.append ("Today:"). /// n "); // info.append (" "amanhã:"). /n "); //} string upttime = jso.get (" "fchh"). // String de temperatura J = JSO.get ("Temp1"). get ("Weather1" ("Weather1" ") .getasstring (); // Today String m_weather = jso.get (" Weather2 "). ("Wind1"). ") .Appnd (j_weather).) .Appnd (j_wind) .Appnd ("/n "); info.append (" "amanhã:"). Appnd ("") .Append (m_wind) .appnd ("/n");} else {// 18 // Temperatura temp1 = jso.get ("temp1"). JSO.get ("Temp2"). 0]; "). Getasstring (); string metethod2 = jso.get (" Weather2 "). ""; (Weather2.Indexof ("Turn")> 0) {// j_weather_part2 = Weather2.split ("Turn") [0];} else {j_weather_part2 = Weather2;} i f (j_weather_part1.equalsignorecase (j_weather_part2)) { j_weather_part1; .IndexOf ("Turn")> 0) {// existe m_weather_part1 = Weather2.split ("Turn") [1];} else {m_weather_part1 = Weather2;} if (metething3.IndexOf ("Turn (" Turn to " )> 0) {// existe m_weather_part2 = meteorologista3.split ("Turn") [0];} else {m_weather_part2 = Weather3;} if (m_weather_part1.equalsignorecase (m_weather_part2)) {m_weather = m_weather_art1; {m_weather = m_weather_part1 + "Turn" + m_weather_part2; /amanhã info.append ("Today:"). ) ;; ("Amanhã:"). }}}}}}}}}}}}}}}}}}}}}}} catch (Exceção e) {} retornar info.tostring ();}
Espera -se que este artigo seja útil para o design do programa Java de todos.