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 7038531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:50+00:00 2026-05-28T01:40:50+00:00

I need to include JSON in my android app, I have followed some tutorials

  • 0

I need to include JSON in my android app,
I have followed some tutorials and have the app reading a test from twitter

package com.or.jsonswitch;

import  ***

public class JsonTestMySwitchActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.d("msg", "app started 1");

    String readResponse = readResponse(); //crea un string llenado por lo que devuelve la funcion()

    try {
        JSONArray jsonArray = new JSONArray(readResponse);
        Log.d("msg", "number of entries::"+jsonArray.length());
        Log.d("msg", "response::"+jsonArray);

    } catch (Exception e) {
        e.printStackTrace(); //donde va el stacktrace?
    }

}

public String readResponse() { //autogenera como private!, cambio a public!

    Log.d("msg" , "entra a buscar");

    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    //HttpGet httpGet = new HttpGet("http://twitter.com/statuses/user_timeline/vogella.json");
    HttpGet httpGet = new HttpGet("http://myswitch.merged.stage.orchard.net.au/LifftService.svc/JSON/CoverageSearchByLatLong/-33.881393,151.214534");

    //httpGet.setHeader("Content-Type", "text/plain; charset=utf-8");
    //httpGet.setHeader("Content-Type", "json");


    try {
        HttpResponse response = client.execute(httpGet); //que es?
        StatusLine statusLine = response.getStatusLine(); //que es?
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) { //200?
            HttpEntity entity = response.getEntity(); //que es?
            InputStream content = entity.getContent(); //que es?
            BufferedReader reader = new BufferedReader(new InputStreamReader(content)); //que es?
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            Log.d("msg" , "Failed to download file");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Log.d("msg", "client protocol exception:"+e);
    } catch (IOException e) {
        e.printStackTrace();
        Log.d("msg", "client protocol exception:"+e);
    }       
    return builder.toString();
}

Note that it works when fetching the JSON data from Twitter:

//HttpGet httpGet = new HttpGet("http://twitter.com/statuses/user_timeline/vogella.json");

but appears blank when fetching from my desired server:

HttpGet httpGet = new HttpGet("http://myswitch.merged.stage.orchard.net.au/LifftService.svc/JSON/CoverageSearchByLatLong/-33.881393,151.214534");

I have no error messages when it returns blank,

do I have to set headers specifying it is JSON? How?

//httpGet.setHeader("Content-Type", "json");
  • 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-05-28T01:40:50+00:00Added an answer on May 28, 2026 at 1:40 am

    found the problem,

    is because the response is not an array, is a dictionary, and I was making the response an array,

    im not in my coding computer so cant post code right now, but that was basically the problem.

    thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON object that I need to pass from the server to
Here's what I need. I need to use https://api.twitter.com/1/statuses/user_timeline.json ?........ query to retrieve tweets
I have am trying to include a JSON parsing library into my app and
I need to include some kind of notifications in a sidebar gadget, preferably systray
I have a .txt file that I need to include into a page, that
I have a prototype model where I need to include the following extension methods
I need to modify the following MySQL statement to include information from a third
I need some help trying to match a C include file with full path
I have some html code I want to store in a database. I need
I need to serialize the strings from a resource file (.resx) into a JSON

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.