Code Monkey home page Code Monkey logo

Comments (12)

JasonYinH avatar JasonYinH commented on May 23, 2024

今天想着替换fastJson的,框架版本都是最新的
image

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024

小伙子,我无法复制你图片上面的代码,另外你图片上面的代码不完整,请提供完整且可复现的代码到这里来。

from gsonfactory.

JasonYinH avatar JasonYinH commented on May 23, 2024
  • assets 文件里的资源
{
  "attitude": 2,
  "collectTime": 1710150586000
}
  • activity 代码
  val json: String = getAssetsString(this, "AbnormalJson.json")
        val mGson = GsonFactory.getSingletonGson()
        val jsonBean = mGson.fromJson(json, aaaa::class.java)
        Log.e("xxx", "" + mGson.toJson(jsonBean))

        val beanToMap = mGson.fromJson(mGson.toJson(jsonBean), MutableMap::class.java)
        Log.e("xxxbb", "" + beanToMap)
  • aaaa 类
class aaaa {
    private var attitude: Int = 0
    private var collectTime: Long = 0L
    override fun toString(): String {
        return "aaaa(attitude=$attitude, collectTime=$collectTime)"
    }
}

from gsonfactory.

JasonYinH avatar JasonYinH commented on May 23, 2024

image

from gsonfactory.

JasonYinH avatar JasonYinH commented on May 23, 2024

https://mikechen.cc/28914.html 用的第一种

from gsonfactory.

JasonYinH avatar JasonYinH commented on May 23, 2024

image
要是用这种反射的方法,将对象转为map就没事了

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024
image image

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024
image

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024

小伙子,经过核实和验证,确实有这个问题,这是由于 Gson 内部将不指定类型的数值统一解析成 double 类型导致的,1710126441000 这个数值会被科学计数法转换成 1.71E+12,但是不代表这样的数值有问题,这两种计数严格意义上讲都没有问题,都是相等的,只不过你更想要显示全数值的那种,而非科学计数值,解决这个问题也很简单,我在框架内部自定义了 ToNumberStrategy 接口策略,对后台返回的数值接收类型进行了优化,如果是浮点数,则用 double 类型装载,如果是整数,则用 int 类型或者 long 类型装载。

image

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024

GsonFactory-9.6.aar.zip

from gsonfactory.

getActivity avatar getActivity commented on May 23, 2024

小伙子,你可以用上面的 aar 包试一下看问题是否被解决?

from gsonfactory.

JasonYinH avatar JasonYinH commented on May 23, 2024

佬,用9.6的包解决了,感谢佬的解决

from gsonfactory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.