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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:04:24+00:00 2026-06-08T04:04:24+00:00

I’m trying to parse Google Places JSON data in Android. I know the URL

  • 0

I’m trying to parse Google Places JSON data in Android. I know the URL I’m passing in works (but I took my key out of the below code). I can get the JSON data to display in a TextView, but now I want to parse it and get (at this point) the first item’s name to display. I modified a tutorial that parsed a twitter feed, and that twittwr tutorial displayed correctly, but my modified code displays nothing. It doesn’t crash, and I don’t get any errors, so I don’t know what’s wrong. So here’s my code:

    public class GetPort extends Activity {

TextView showJSdata;
HttpClient client;
JSONObject json;

final static String pURL = "https://maps.googleapis.com/maps/api/place/search/json? location=30.487263,-97.970799&radius=25000&types=airport&sensor=false&key=MY_KEY";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mn_test3);
    showJSdata = (TextView)findViewById(R.id.http_tv);
    client = new DefaultHttpClient();
    new ReadURL().execute("name");
}

public JSONObject showPorts() 
throws ClientProtocolException, IOException, JSONException{

    StringBuilder portURL = new StringBuilder(pURL);        
    HttpGet get = new HttpGet(portURL.toString());
    HttpResponse r = client.execute(get);
    int status = r.getStatusLine().getStatusCode();
    if(status == 200){
        HttpEntity e = r.getEntity();
        String data = EntityUtils.toString(e);
        JSONArray timeline = new JSONArray(data);
        JSONObject lastport = timeline.getJSONObject(0);
        return lastport;
    }else{
        Toast.makeText(GetPort.this, "oops", Toast.LENGTH_SHORT);
        return null;
    }

}

public class ReadURL extends AsyncTask<String, Integer, String>{

    @Override
    protected void onPostExecute(String result) {
        showJSdata.setText(result);
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            json = showPorts();
            return json.getString(params[0]);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return null;
    }

}

}

Can anyone see where the code fails, or where I went wrong?

  • 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-08T04:04:26+00:00Added an answer on June 8, 2026 at 4:04 am

    Well, I changed your code a bit and got the following result:

    Cedar Park Regional Medical Center
    

    If that’s what it’s suppose to give, the code is this:

    if(status == 200){
        HttpEntity e = r.getEntity();
        String data = EntityUtils.toString(e);
        JSONObject jsonObject = new JSONObject(data);
        JSONArray timeline = jsonObject.getJSONArray("results");
        JSONObject lastport = timeline.getJSONObject(0);
        return lastport;
    }
    

    You could see the entire output by pasting it to the address line of your browser.
    also note you have a space in there after the json? part in the url.
    You need first to create an object from the data, then parse it. Taking the array names as results
    then getting any objects in that, and taking its string.

    Also, when I ran your code (with my API key) I did get errors, not fatal error which crashes your app, but error in parsing JSON (appeared in orange in the logcat)

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.