Java

public class myStation {

public static String getTempr() {

HttpGet request = new HttpGet("http://openweathermap.org/data/2.1/weather/station/46933?type=json");

AndroidHttpClient client = AndroidHttpClient.newInstance("Android");

HttpResponse response = null;

try {

response = client.execute(request);

} catch (IOException e) {

e.printStackTrace();

return "Error executing request";

}

client.close();

ByteArrayOutputStream out = new ByteArrayOutputStream();

if (response != null) {

try {

response.getEntity().writeTo(out);

out.close();

} catch (IOException e) {

e.printStackTrace();

return "Error on response";

}

String responseString = out.toString();

JSONObject resp;

try {

resp = new JSONObject(responseString);

float tt = Float.valueOf(resp.getJSONObject("main").getString("temp")) - 273;

return "t=" + String.format("%.2f", tt) + "°C";

} catch (JSONException e) {

e.printStackTrace();

return "Error parsing JSON";

}

}

return null;

}

}