0

I have a PHP web service whill pulls data out of a MySQL database.

I have an Android app which calls the service.

Locally on my WAMP Server everything works fine but I just uploaded the data/service to a domain and testing against that.

I am getting this error:

org.json.JSONException: Value  at Latitude of type java.lang.String cannot be converted to double

From this line of code:

double latitude = thisVenue.getDouble(TAG_LATITUDE);

And the value (taking from the log via Android Studio) which causes this error is:

"Latitude":"51.05279"

I cannot see why that value cannot be converted to a double. Locally my app can parse the same dataset no problem so I presume it has something to do with how it is stored/retrieved?

Edit: Here is one of the objects returned in JSON, notice all values have quotes

{"VenueID":"4","ListingID":"19","Name":"TempName1","Location":"207 10A St NW","DayOfWeek":"Mon","Featured":"0","FeaturedDistanceRange":"0","Latitude":"51.05279","Longitude":"-110.087509","StartHour":"4","StartHourType":"pm","StartMinute":"0","EndHour":"7","EndHourType":"pm","EndMinute":"0"}

And I format it as JSON like so:

    header("Content-type: application/json");
    print(json_encode(array('venues'=>$data)));
andrewb
  • 2,995
  • 7
  • 54
  • 95
  • Take a peek here and check your chars... http://stackoverflow.com/questions/13368739/jsonexception-value-of-type-java-lang-string-cannot-be-converted-to-jsonobject – puj Mar 14 '15 at 00:03
  • This is standard JSON response. Everything comes back quoted – andrewb Mar 14 '15 at 00:03

2 Answers2

0

As the data from the server is not a double, u must use as this

double latitude = Double.valueOf(thisVenue.getString(TAG_LATITUDE));
ch271828n
  • 15,854
  • 5
  • 53
  • 88
0

Check you are getting a valid double back from the getDouble() method (the compiler doesn't think you are. If the following compiles and throws a NumberfFormatException at runtime then you know you're not getting a valid double. And "Latitude":"51.05279" doesn't look like a parseable double, "51.05279" would be fine.

double latitude = Double.parseDouble(thisVenue.getDouble(TAG_LATITUDE));
  • "Latitude" is the JSON key.I do get a NumberFormatException: Caused by: java.lang.NumberFormatException: Invalid double: "" – andrewb Mar 14 '15 at 00:14