Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:17:47+00:00 2026-06-17T10:17:47+00:00

I use the class below to get some JSON data. The strange thing is,

  • 0

I use the class below to get some JSON data. The strange thing is, I can’t parse JSON only from the url I need to test the app (server-side not maintained by me): if you click on this link, you will be able to see JSON data in your browser. But when I try to parse it programmatically, it throws a JSONException.

  01-03 11:08:23.615: E/JSON Parser(19668): Error parsing data org.json.JSONException:    Value <html><head><title>JBoss of type java.lang.String cannot be converted to JSONObject

I tried to test it with http://ip.jsontest.com/ and http://api.androidhive.info/contacts, it works nicely! Exception is only thrown while trying to parse JSON from my 1st link. I thought it could be a server problem, but I’m able to see JSON data with a browser.. just can’t explain that.

   public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

/* default constuctor*/
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url) {

   /* get JSON via http request */
    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        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();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    /* try to parse the string to JSON Object*/
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

 /* return JSON String */
    return jObj;

      }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:17:48+00:00Added an answer on June 17, 2026 at 10:17 am

    Using the BufferedReader approach will fetch you the HTML source of that page, which is why you see HTML tags like < html>< head>< title> in your string. Instead, use EntityUtils to get the JSON string:

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    
    try {
        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
    
        int status = httpResponse.getStatusLine().getStatusCode();
    
        if (status == HttpStatus.SC_OK) {
            String jsonString = EntityUtils.toString(httpEntity);
            try {
                JSONObject jsonObject = new JSONObject(jsonString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use class Matrix4x4 from some 3rd party library, and I need
I am new to Mockito. Given the class below, how can I use Mockito
I have this code below. I need to use a class id instead of
I need to have some data members get some values when I create an
I have a general question on the class definition and its use..THe below code
I use class from How to support Arabic text in Android? to show Arabic
Hello all I was hoping to get some help with inported this class to
One can accomplish same thing using different tools. So have I in examples below.
I'm trying to use the CustomMetaKeyCriteria class to pull back content from the Broker
I am trying to use KO templates to parse a JSON file ( see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.