Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.berko.tictactoe;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.content.Context;
- public class GetJSON {
- Context context = MainActivity.context;
- public static JSONObject getJSONfromURL(String url) {
- JSONObject jArray = null;
- HttpClient client = new DefaultHttpClient();
- HttpGet request = new HttpGet(url);
- String html = "";
- InputStream in;
- try {
- HttpResponse response = client.execute(request);
- in = response.getEntity().getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- StringBuilder str = new StringBuilder();
- String line = null;
- while((line = reader.readLine()) != null)
- {
- str.append(line);
- }
- in.close();
- html = str.toString();
- } catch (IllegalStateException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- jArray = new JSONObject(html);
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return jArray;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement