ตัวอย่างของบทความนี้บอกวิธีที่ Java เรียกว่า China Weather Network API เพื่อรับข้อมูลการพยากรณ์อากาศ แบ่งปันสำหรับทุกคนสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
// ใช้ Bingcheng Harbin เป็นตัวอย่างในการโทรหาข้อมูลสภาพอากาศผ่าน API สภาพอากาศของจีน ResponseHandler <String> ResponceHandler = ใหม่ BasicResponseHandler (); jsonobject jso = jse.getasjsonobject () j = jso.get ("temp1") เงื่อนไข // สตริง j_weather = jso.get ("Weather1") // ทิศทางลมและลม // สตริง j_wind = jso.get ("wind1") // info.append ("วันนี้:") /// n "); // info.append (" พรุ่งนี้: ") /n "); //} updtime uptime = jso.get (" "fchh") // อุณหภูมิ j = jso.get ("temp1") รับ ("Weather1" ("Weather1" ") .getAstString (); // วันนี้สตริง m_weather = jso.get (" Weather2 " ("Wind1") ") .Appnd (j_weather).) .Appnd (j_wind) .Appnd ("/n "); info.append (" พรุ่งนี้: ") appnd ("") .append (m_wind) .appnd ("/n");} else {// 18 // อุณหภูมิสตริง temp1 = jso.get ("temp1") jso.get ("temp2") 0]; สตริง m = temp2.split ("~") [1] + "~" + temp3.split ("~") [0]; "). 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 ("Turn") [0];} else {j_weather_part2 = Weather2;} ฉัน f (j_weather_part1.equalsignorecase (j_weather_part2) j_weather_part1; .indexof ("Turn")> 0) {// มี m_weather_part1 = Weather2.split ("Turn") [1];} else {m_weather_part1 = Weather2;} ถ้า (สภาพอากาศ )> 0) {// มี m_weather_part2 = Weather3.split ("Turn") [0];} else {m_weather_part2 = Weather3;} ถ้า (m_weather_part1.equalsignorecase (m_weather_part2)) {m_weather = m_weather_part1; {m_weather = m_weather_part1 + "turn" + m_weather_part2; /tomorrow info.append ("วันนี้:") ) ;; ("" พรุ่งนี้: "). ผนวก (m) .Appnd (" ") .Appnd (m_weather) }}}}}}}}}}}}}}}}}}}}}}}}} catch (Exception E) {} return info.toString ();};
หวังว่าบทความนี้จะเป็นประโยชน์กับการออกแบบโปรแกรม Java ของทุกคน