Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

float类型和double类型为空字符串时反序列化失败 #479

Closed
lizhangqu opened this issue Jan 9, 2016 · 4 comments
Closed

float类型和double类型为空字符串时反序列化失败 #479

lizhangqu opened this issue Jan 9, 2016 · 4 comments

Comments

@lizhangqu
Copy link

{
"doubleParam": "",
"extra": {
"doubleParam": "12.23",
"floatParam": ""
},
"floatParam": "2.76"
}

当float和double类型是空字符串时反序列化失败,int,long则不存在该问题

版本1.1.46.android 看log 1.1.45说已经修复了这个问题,但是1.1.46还是存在

@dachuanz
Copy link

使用新版吧

@lizhangqu
Copy link
Author

就是android的最新版存在的问题

@dachuanz
Copy link

是1.2.4的版本吗?
我看1.2.4的代码应该解决了

 public static final Float castToFloat(Object value) {
        if (value == null) {
            return null;
        }

        if (value instanceof Number) {
            return ((Number) value).floatValue();
        }

        if (value instanceof String) {
            String strVal = value.toString();
            if (strVal.length() == 0) {
                return null;
            }

            if ("null".equals(strVal) || "NULL".equals(strVal)) {
                return null;
            }

            return Float.parseFloat(strVal);
        }

        throw new JSONException("can not cast to float, value : " + value);
    }

@wenshao
Copy link
Member

wenshao commented Apr 11, 2016

已经修复,将会在1.1.49.android和1.2.9版本中发布,等待新版本吧。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants