0

I have the error message:

error in executing get org.json.JSONException: Value org.apache.http.message.BasicHttpResponse@ed9ee8a of type java.lang.String cannot be converted to JSONObject

And the following code:

 response = httpclient.execute(httpget);

        JSONObject locationObj = new JSONObject(String.valueOf(response));
        JSONObject locationInfo = locationObj.getJSONObject("item");
        lat = locationInfo.getInt("lat");
        lon = locationInfo.getInt("lon");

I don't want to return the string, I want to get the items from the JSON string and use them for a google map.

String json = "{\"info\": {" +"\"lat\": " + locationGet.getLat() + ", " +   "\"lon\": " + locationGet.getLon() + "} }";
z_blue
  • 350
  • 3
  • 20
bananabreadbob
  • 369
  • 2
  • 10
  • 26

1 Answers1

0
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(stringToParse);

See How to convert String to JSONObject in Java (The answer by Mappan, not the accepted answer)

Community
  • 1
  • 1
z_blue
  • 350
  • 3
  • 20