简体   繁体   English

Gson JsonSyntaxException:java.lang.NumberFormatException

[英]Gson JsonSyntaxException: java.lang.NumberFormatException

I am having error while parsing a Json with Gson into an object. 将带有GsonJson解析为对象时出现错误。 What I am trying to do is store the latitude longitude in the double variable but while parsing, I am getting an error. 我正在尝试将纬度经度存储在double变量中,但是在解析时出现错误。 I try to change the class variables and the gson to string but still getting the same error. 我尝试将类变量和gson更改为字符串,但仍然遇到相同的错误。 The json it´s on github. github上的json。

The error that i get is: 我得到的错误是:

com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 32.93644801 at line 7 column 22 path $.bars[0].lat

json data is: json数据是:

{
    "bars":[
        {
            "name": "Antares Pichincha",
            "place_id": "ChIJOR29Pk-rt5UR0hsdFVQWpD8",
            "logo_src": "antares",
            "lat": -32.936448000001,
            "lng": -60.6587110
        }
    ]
}

and the class reciving the data is 接收数据的类是

public class BarList {

    //@SerializedName("bars")
    List<Bar> bars;

    public List<Bar> getBars(){
        return bars;
    }
}

public class Bar {

    private String name;
    private String place_id;
    private String logo_src;
    private double lat;
    private double lng;

    public Bar(String name, String place_id, String logo_src, double lat, double lng) {
        this.name = name;
        this.place_id = place_id;
        this.logo_src = logo_src;
        this.lat = lat;
        this.lng = lng;
    }

and here is where I call it 这就是我所说的

GsonRequest<BarList> request = new GsonRequest<BarList>(
                JSON_URL,
                BarList.class,
                null,
                new Response.Listener<BarList>() {
                    @Override
                    public void onResponse(BarList response) {
                        barList = response;
                        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                                .findFragmentById(R.id.map);
                        mapFragment.getMapAsync(MapsActivity.this);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d(TAG, "Error Respuesta en JSON: " + error.getMessage());
                    }
                }
        );

Someone have any idea how can i solve this? 有人知道我该如何解决?

不确定这是否是您的问题,但是bar数组仅包含一个元素,但第9行是逗号,后面应跟另一个元素。

I ask to a developer friend to take a look at the code and he could not find any problems or errors on the code, so he told me to delete the installed app on the device and re-build the project and that solve the issue. 我请一位开发人员朋友看一下代码,他在代码上找不到任何问题或错误,因此他告诉我删除设备上已安装的应用程序并重新生成项目,然后解决了该问题。

Thanks everyone for the answers. 谢谢大家的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM