akhyrul

Contoh GET JSON pake AsyncHttpClient

Aug 19th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. AsyncHttpClient client = new AsyncHttpClient();
  2.  
  3. client.get(ENDPOINT_URL + Uri.encode(city + "," + country),
  4.         new JsonHttpResponseHandler() {
  5.             public void onSuccess(JSONObject result) {
  6.                 try {
  7.                     int code = result.getJSONObject("cond").getInt(
  8.                             "code");
  9.                     int temp = result.getJSONObject("cond").getInt(
  10.                             "temp");
  11.                     Log.i("hae", "Weather Code :: " + code);
  12.                     Log.i("hae", "Weather Temp :: " + temp);
  13.                     // BLA BLA BLA
  14.                 } catch (JSONException e) {
  15.                     e.printStackTrace();
  16.                 }
  17.             }
  18.  
  19.             public void onFailure(Throwable e, String content) {
  20.                 e.printStackTrace();
  21.                 Toast.makeText(getApplicationContext(),
  22.                         "Failed to get weather data",
  23.                         Toast.LENGTH_SHORT).show();
  24.             }
  25.         });
Advertisement
Add Comment
Please, Sign In to add comment