英文:
Parsing 64-bit int on appspot.com different then on localhost?
问题
当您尝试在JavaScript中解析一个64位整数时(parseInt("5838406743490560")
),它在本地服务器上可以工作,但在Appspot.com服务器上却不行。在appspot.com服务器上,您需要将其解析为字符串而不是int64
。有人知道为什么会这样吗?
在本地主机上,我可以这样做:
type Entity struct {
List []*Message `json:"list"`
}
type Message struct {
Id int64 `json:"id" datastore:"-"`
}
将其上传到appspot.com后,我需要将其解析为字符串,否则会出现下面的错误消息。
type Entity struct {
List []*Message `json:"list"`
}
type Message struct {
Id int64 `json:"id,string" datastore:"-"`
}
发送的包中id=parseInt("5838406743490560")
:
[{
"jsonrpc": "2.0",
"id": "gapiRpc",
"method": "service.datastore.delete",
"apiVersion": "v0",
"params": {
"list": [{
"id": 5838406743490560
}]
}
}]
-
在Appspot.com上,我无法使用
json:"id" datastore:"-"
进行解组。 -
在本地主机上,它完美运行。
仅在Appspot.com上出现的错误:
[
{
"error": {
"code": 400,
"message": "json: cannot unmarshal string into Go value of type int64",
"data": [
{
"domain": "global",
"reason": "badRequest",
"message": "json: cannot unmarshal string into Go value of type int64"
}
]
},
"id": "gapiRpc"
}
]
我正在使用SDK v1.9.6。
英文:
When you try to parse a 64-bit integer in JavaScript (parseInt("5838406743490560")
) it works on the localhost server but not on the Appspot.com server. On the appspot.com server you need to parse it as a string instead of a int64
. Does anyone know why that is?
On localhost I can do this:
type Entity struct {
List []*Message `json:"list"`
}
type Message struct {
Id int64 `json:"id" datastore:"-"`
}
After uploading it to appspot.com, I need to parse it as a string or I get the error message below.
type Entity struct {
List []*Message `json:"list"`
}
type Message struct {
Id int64 `json:"id,string" datastore:"-"`
}
Package that gets sent where id=parseInt("5838406743490560")
:
[{"jsonrpc":"2.0","id":"gapiRpc","method":"service.datastore.delete","apiVersion":"v0","params":{"list":[{"id":5838406743490560}]}}]
-
On Appspot.com I can not unmarshal using
json:"id" datastore:"-"
. -
On localhost it works perfect.
Error on Appspot.com only:
[
{
"error": {
"code": 400,
"message": "json: cannot unmarshal string into Go value of type int64",
"data": [
{
"domain": "global",
"reason": "badRequest",
"message": "json: cannot unmarshal string into Go value of type int64"
}
]
},
"id": "gapiRpc"
}
]
I am using SDK v1.9.6.
答案1
得分: 2
我的本地主机运行在64位环境上,而appspot.com运行在32位环境上。所有小于2147483647的数字都可以正常解析,但是尽管被定义为int64类型,ID 5838406743490560太大无法适应32位环境,因此在appspot.com实例中被解析为字符串。
英文:
My localhost is running on a 64bit environment and appspot.com on a 32bit. All numbers smaler then 2147483647 parse ok, but although defined as int64 the id 5838406743490560 is to big to fit into 32bit therefore it get parsed as a string on a appspot.com instance.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论