Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MalformedJsonException: Expected name at line

Tags:

json

android

gson

I've got a JSON string and this is just a part of it:

"geoLocation":{
    "latitude": 46.05570,
    "longitude": 14.50705,
},

I've also got a custom class and I'm trying to use GSON to get array of objects from this JSON like this:

locationList = gson.fromJson(responseString, Location[].class);

But the app crashes on the line above and this is the Logcat:

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 15 column 6 path $[0].geoLocation.

This is how the part of the class with geoLocation variables looks like:

public class Location {
    ...
    private double latitude;
    private double longitude;
    ...
}

Any idea why I'm getting the crash?

like image 202
Guy Avatar asked Apr 16 '15 20:04

Guy


1 Answers

"geoLocation":{
    "latitude": 46.05570,
    "longitude": 14.50705,
}

comma after longitude is invalid. Remove it.

like image 129
Alexander Zhak Avatar answered Sep 17 '22 05:09

Alexander Zhak