Skip to content

Instantly share code, notes, and snippets.

@ajamaica
Last active December 27, 2015 19:39
Show Gist options
  • Save ajamaica/7378013 to your computer and use it in GitHub Desktop.
Save ajamaica/7378013 to your computer and use it in GitHub Desktop.
AsyncTask de Jsonusonew MinutoMinAsync().execute("http://www.copalive.com/api/json/match/live/"+ c.espn_id +"?l=es");
HTTPAsync().execute("http://www.copalive.com/api/json/match/live/");
private class HTTPAsync extends AsyncTask<String, Void, String> {
InputStream is = null;
String json = "";
@Override
protected String doInBackground(String... urls) {
// Making HTTP request
String result = "";
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(urls[0]);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
return result;
}
@Override
protected void onPostExecute(String result) {
Log.i(result);
/// AQUI VA EL PARSEO
try {
//jArrayObject = new JSONArray(result);
/*JSONObject[] data = new JSONObject[jArrayObject.length()];
for (int i = 0 ; i < jArrayObject.length(); i++){
data[i] = jArrayObject.getJSONObject(i);
}
minutolist.setAdapter(new MinutoAdapter(MinutoActivity.this,R.layout.minuto_list_item,data));
*/
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment