Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public JSONArray getJSONFromUrl(String url) {
- 22
- 23
- // Making HTTP request
- 24
- try {
- 25
- // defaultHttpClient
- 26
- DefaultHttpClient httpClient = new DefaultHttpClient();
- 27
- HttpPost httpPost = new HttpPost(url);
- 28
- HttpResponse httpResponse = httpClient.execute(httpPost);
- 29
- HttpEntity httpEntity = httpResponse.getEntity();
- 30
- is = httpEntity.getContent();
- 31
- } catch (UnsupportedEncodingException e) {
- 32
- e.printStackTrace();
- 33
- } catch (ClientProtocolException e) {
- 34
- e.printStackTrace();
- 35
- } catch (IOException e) {
- 36
- e.printStackTrace();
- 37
- }
- 38
- try {
- 39
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- 40
- is, "iso-8859-1"), 8);
- 41
- StringBuilder sb = new StringBuilder();
- 42
- String line = null;
- 43
- while ((line = reader.readLine()) != null) {
- 44
- sb.append(line + "n");
- 45
- }
- 46
- is.close();
- 47
- json = sb.toString();
- 48
- } catch (Exception e) {
- 49
- Log.e("Buffer Error", "Error converting result " + e.toString());
- 50
- }
- 51
- // try parse the string to a JSON object
- 52
- try {
- 53
- jObj = new JSONArray(json);
- 54
- } catch (JSONException e) {
- 55
- Log.e("JSON Parser", "Error parsing data " + e.toString());
- 56
- }
- 57
- // return JSON String
- 58
- return jObj;
- 59
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement