当您尝试在 JavaScript (parseInt("5838406743490560")
) 中解析 64 位整数时,它可以在本地主机服务器上运行,但不能在 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。
最佳答案
我的本地主机在 64 位环境中运行,appspot.com 在 32 位环境中运行。所有比 2147483647 小的数字都可以解析,但尽管定义为 int64,但 id 5838406743490560 太大以适应 32 位,因此它在 appspot.com 实例上被解析为字符串。
关于google-app-engine - 在 appspot.com 上解析 64 位 int 与在本地主机上不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24441960/