top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to receive json array from server?Android app development

+3 votes
260 views

I want to fetch details of particular objects inside my activity.How can I get it.

posted Mar 6, 2016 by Shivam Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Check the following code which receives the JSON array from the server for the given URL (http://tech.queryhome.com/json-request/check-login ) and returns the value of the error (Let me know if looking something different) -

public Boolean check_login(String url)
{
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpEntity httpEntity = null;
    HttpResponse httpResponse = null;
    String response = null;
    JSONObject jsonObject;
    Boolean mylogin=false;

    HttpGet httpGet = new HttpGet(url);

    try {
        httpResponse = httpClient.execute(httpGet);

        httpEntity = httpResponse.getEntity();
        response = EntityUtils.toString(httpEntity);
    }
    catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }


    try {
        jsonObject = new JSONObject(response);
        mylogin = jsonObject.getBoolean("error");
    }
    catch (JSONException e) {
        e.printStackTrace();
    }

    return mylogin;
}
answer Mar 7, 2016 by Salil Agrawal
Similar Questions
+2 votes

I want to send a json array to server,how I can achieve this?

+3 votes

how can install apk through ADB in android device.

+1 vote

I have a bunch of content (school text book type including images, equations, text, graphs etc ., that need to be made available for consumption on an Android App. Have tried doc parsing to JSON but it appears there are limitations of JSON (such as lack of adequate image support, support for special characters including math equations and so on.

Can someone recommend good, content publishing suite that allows delivery over mobile ? thanks Sridhar

...