Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdb查询结果json转换丢失精度 #1747

Closed
qinyuguang opened this issue Apr 11, 2022 · 1 comment
Closed

gdb查询结果json转换丢失精度 #1747

qinyuguang opened this issue Apr 11, 2022 · 1 comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@qinyuguang
Copy link
Contributor

go 1.17
gf v2.0.6

生成gjson.Json类型的entity,查询结果会丢失精度。实际是在gconv.Struct时丢失的
下面用gconv.Struct复现

package main

import (
	"github.com/gogf/gf/v2/container/gvar"
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/util/gconv"
	"github.com/gogf/gf/v2/util/gutil"
)

func main() {
	var json *gjson.Json
	_ = gconv.Struct(gvar.New("[1, 2, 336371793314971759]"), &json)
	gutil.DumpWithType(json)
}

输出丢失精度
*gjson.Json(24) "[1,2,336371793314971800]"

@gqcn

gqcn added a commit that referenced this issue Apr 11, 2022
@gqcn gqcn added bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. labels Apr 11, 2022
@gqcn gqcn closed this as completed Apr 11, 2022
@qinyuguang
Copy link
Contributor Author

补充gdb操作

数据库

CREATE TABLE test_json (
	"data" json NOT NULL
);
INSERT INTO test_json ("data") VALUES('[1, 2, 336371793314971759]');

代码

package main

import (
	_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
	_ "github.com/lib/pq"

	"context"

	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/frame/g"
)

type TestJson struct {
	Data *gjson.Json `json:"data"`
}

func main() {
	var res *TestJson
	if err := g.DB().Model("test_json").Scan(&res); err != nil {
		g.Log().Debug(context.Background(), "err:", err)
	}
	g.DumpWithType(res)
}

输出

*TestJson(1) {
    Data: *gjson.Json(24) "[1,2,336371793314971800]",
}

qinyuguang pushed a commit to qinyuguang/gf that referenced this issue Apr 11, 2022
qinyuguang pushed a commit to qinyuguang/gf that referenced this issue Apr 12, 2022
qinyuguang pushed a commit to qinyuguang/gf that referenced this issue Apr 12, 2022
gqcn added a commit that referenced this issue Apr 18, 2022
houseme pushed a commit to houseme/gf that referenced this issue Apr 18, 2022
houseme pushed a commit to houseme/gf that referenced this issue Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants