引起:java.lang.NumberFormatException:无效的double:""空白值 [英] Caused by: java.lang.NumberFormatException: Invalid double: "" with blank value

查看:208
本文介绍了引起:java.lang.NumberFormatException:无效的double:""空白值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON 字符串有一些空白值时,我得到了错误,从服务器获取,
如何处理空白值
这里是JSON

I get ther error when JSON string have some blank value, getting from server, how to deal with blank values here is JSON

{  
   "status":"success",
   "data":[  
      {  
         "id":"1",
         "name":"ABC",
         "address":"ABC, QWE",
         "lat":"16.799999",
         "lng":"96.150002",
         "admin_id":"4",
         "is_approved":"1",
         "added":"2015-08-07 11:17:12",
         "status":"1",
         "image_file":"",
         "image_width":"",
         "image_height":""
      }
   ]
}

Gson gson = new GsonBuilder().serializeNulls().create();
Type listType = new TypeToken<List<MyData>>() {}.getType();
myDataArrayList = gson.fromJson(response.getString("data"), listType);

在MyData类中,我试图更改 lat,long 键入 int 并在json中更改了相同但仍显示相同错误的值

In MyData class I tried to change lat, long type int and changed value in json also for the same but still showing same error

public class MyData implements Parcelable {

    public int id;

    public String name;

    public String address;

    public String lat;

    public String lng;

    public String added;

    public int status;

    public String image_file;

    public int image_width;

    public int image_height;

}

此行显示错误

myDataArrayList = gson.fromJson(response.getString("data"), listType);


推荐答案

在MyData中将image_width和image_height的类型更改为String Class

Change the type of image_width and image_height to String in MyData Class

public String image_width;

public String image_height;

因为int将无法存储此字符串,并且在使用它时可以将其解析为int。

As int will not be able to store "" this string, and at the time of using it you can parse it into int.

这篇关于引起:java.lang.NumberFormatException:无效的double:&quot;&quot;空白值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆