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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:46:40+00:00 2026-05-22T22:46:40+00:00

I’m writing an android app that takes your current location and returns a list

  • 0

I’m writing an android app that takes your current location and returns a list of the stores near you using the Google Places web service. I’m able to get back (what I think is) valid JSON, but when I go to parse the JSON using the Android JSONObject library, I get a parsing error.

Here is my class:

public class StoresNearMe {

    private String result = "";  
    private String googleAPIKey = "Omitted for this example"; 
    private String searchRadius = "50";
    private Location myLocation;
    final String TAG = getClass().getSimpleName();  

    public StoresNearMe(Location location){
        myLocation = location;
    }//StoresNearMe

    public String getStoresNearMe(){
        String result = "Nothing";
        result = callGoogleWebService(buildURLForGooglePlaces(myLocation));
        convertJSONtoArray(result);
        return result;
    }//getStoresNearMe


    private String callGoogleWebService(String url){  
            HttpClient httpclient = new DefaultHttpClient();  
            HttpGet request = new HttpGet(url);  
            //request.addHeader("deviceId", deviceId);  
            ResponseHandler<String> handler = new BasicResponseHandler();  
            try {  
                result = httpclient.execute(request, handler);  
            } catch (ClientProtocolException e) {  
                e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
            httpclient.getConnectionManager().shutdown();  
            return result;
    }//callWebService

    private String buildURLForGooglePlaces(Location location){
        String baseUrl = "https://maps.googleapis.com/maps/api/place/search/json?";
        String lat = String.valueOf(location.getLatitude());
        String lon = String.valueOf(location.getLongitude());
        String url = baseUrl + "location=" + lat + "," + lon + "&" +
                     "radius=" + searchRadius + "&" + "sensor=false" +
                     "&" + "key=" + googleAPIKey;
        Log.d(TAG,url);
        return url;
    }//buildURLForGooglePlaces

    private void convertJSONtoArray(String rawJSON){
        try {
            JSONObject completeJSONObj = new JSONObject(rawJSON);
            String json = completeJSONObj.toString();
            Log.d(TAG,json);
            JSONObject results = completeJSONObj.getJSONObject("results");
        } catch (JSONException e) {
            Log.d(TAG,"JSON parsing error - fix it:" + e.getMessage());
        }
    }//convertJSONtoArray
}//StoresNearMe

Here is the JSON returned by my call:

{
   "html_attributions" : [
      "Listings by \u003ca href=\"http://www.yellowpages.com.au/\"\u003eYellow Pages\u003c/a\u003e"
   ],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : -33.86694910,
               "lng" : 151.19549870
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "96760d4544ecdaaf2e87565915638238ca960f20",
         "name" : "Pirrama Rd",
         "reference" : "CnRqAAAAL0xKaK8vGlVlD-E5j-88K9YTuCKlOFfoBxhBUwMIBGxNQDC8UdkULJiiC0ICBRxpddCV09wyc-HtShEpquP-drX4sj4tI_tbfveDIbzfSAUaNQjYhhfjQ-eVi0VeWBXdXH0A8Z_-nKXKMo1fvCHtBhIQlAeLnFtotWnYonMUpU1DqxoUcI1weYioNnJPtnhXCThmx0W0ubU",
         "types" : [ "route" ],
         "vicinity" : "Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8669710,
               "lng" : 151.1958750
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
         "name" : "Google Sydney",
         "reference" : "CnRkAAAAqvesgoigCyiZfDUwqjbravZHH5zsXrmskbQVhkFk1JMnnrnKNGQyoHBBYofTML_zZqaAUAKJeJCvReUn62oGzSgPgNSjWaXUVorKGDXAAjhGyeh2pRrJFwuC5qsgBYdyN4kY8kspJGu_bMo3xrranxIQ-mFIK_28TAqiagOAzY7RiBoUrZTvFJYSn0OXimLRRb_SQ3OKW44",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Road, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8670840,
               "lng" : 151.195950
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "27e84d1acda19c14b9c7f5271242796891bc9c9e",
         "name" : "Accenture",
         "reference" : "CoQBfQAAAOpBriMi1e4itUquHQnv_jQyEOibrEnbWfAuJBJqBUzcTqNvY6luCcgiqHr3ensEO81bcTkt4fXGHFLxM7pERmxVvFnRnLsLy5xyQtVxIp8eQnYP6AZxLZyxbfGceG87r6A1lHCOQTFxK85HVFq7pYik9ud_ExxEtwHT3gO54pihEhDYEZ59AYpLMDmlRHk5__q_GhQdTS2wSOU2sAxy0j4J7EYwCuq6Iw",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Road, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8670520,
               "lng" : 151.1957360
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "3ef986cd56bb3408bc1cf394f3dad9657c1d30f6",
         "name" : "Doltone House - Darling Island Wharf",
         "reference" : "CoQBewAAAExUq-YlS-bahqAJeJbfyGfkUrqyuKjZgCPxHznMZsHg1aHLWoFk8s_04DxDtEFAlSyRP-ZHNsceha6MB8JD7zFMjbYOKNJLSm9OcgFUOFB-4SZP3ZeRyYzna2032gayzUU1_8N-qtb_r2kfllGYAmgnaU7h6RC8haaf-dFfvdiiEhBUdWHpEeL7qwtB91BgNYdPGhTAjf0Xa7-MKHJRRCQu_g7XL80dzQ",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Road, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8671110,
               "lng" : 151.1958750
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "258f23471a33cfa2828170660d94cd5797edb18c",
         "name" : "Workplace6",
         "reference" : "CnRhAAAAi_hm5c3gpntkNvC7NbQtIe5tcmosCIHHbzqhLURaH7mQ6inEOqg47_cltBrtFBEPSIqCuPQDC3UA-suLBfRslIwUNytKjC87Lt1ZrGXF6ZmnOR2rVcdCGdoWrdi977RHruBO21zbjzVWE-A3ZDn2NBIQ1Vu2-nr3E02DuJAtXL8x4BoUEBRWEHReK2LO3IoldvyyvSKb0Qs",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Rd, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8670520,
               "lng" : 151.1957360
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "fe9136d6406ed2d35660dea37a0be34043c1a4f2",
         "name" : "Doltone House",
         "reference" : "CnRjAAAAo4zx1lM-veFEPBBeIRFETZoH8QRMmpHIBVtnmfOZ-Sh1-8p4vxKj-146pHGW6wPCZxIV0iIuAGow9OSsHubvY_kSnlBe5OB99ZSxHQsm0LrLh45c05Gf7C8jwp_9D7keDVDAC47MN65niSZW71fOrRIQxODppLktQZFWbf-V1N4gHxoUPetbj0zbU1kQj96YrRLzLKrbMoE",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Road, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.8666470,
               "lng" : 151.195650
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "2722b46120160ec0a322e0a13cb0717ed41a696b",
         "name" : "Biaggio",
         "reference" : "CmRdAAAAp7wiB1b9cK-26FjhO2DVAGA-5uzuZxppHqCkR75dQxoMJiLD5G7H90_dKtNVDlRAdKSOx7hWlUoHGuwkbBA4ZhNIDrPdLWQ1a41sEN9gZJvU-t7uxoRzziZpTVSCU-AXEhDoQ36icc3OBaMH1xxnPgsEGhTB08nD6Q67ojrGYMJWrd4PojJKsw",
         "types" : [ "establishment" ],
         "vicinity" : "Pirrama Rd, Pyrmont"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -33.86954560,
               "lng" : 151.19454040
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "40840d476baa531e0227a353b1bef70262f66e7e",
         "name" : "Pyrmont",
         "reference" : "CnRnAAAA7aHZwg2JyjTI-xotS1q4XKgbg3eCUwOZm3Nz55Xf5Q2w-nZpBrrd2VAEl60On0puVl8bX7UaJTIECELr3KY2mL4s7zsIznItOiJEG-9QMlnreRSmxSBSUAkPghKWoq4OFbCr0dwNtZSKJFazcbCc1BIQSz5BZfCm-iyMZ8YOgvc4tBoU1CdnwsHS5PhB69jpYHsOvfWXEgo",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

Any help is appreciated – I’m not sure what is going wrong.

Thanks!

  • 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-22T22:46:41+00:00Added an answer on May 22, 2026 at 10:46 pm

    The problem is that you’re trying to read an array in as an object.

    Change

    JSONObject results = completeJSONObj.getJSONObject("results");
    

    to

    JSONArray results = completeJSONObj.getJSONArray("results");
    

    and the parse exception goes away.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.