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

rpc将int变成科学计数法 #16

Open
chenxi2015 opened this issue Mar 9, 2023 · 3 comments
Open

rpc将int变成科学计数法 #16

chenxi2015 opened this issue Mar 9, 2023 · 3 comments

Comments

@chenxi2015
Copy link

源数据:
{ "refund_order_id":1870381757955251, }

转义成:
{ "refund_order_id":1.8703817579553E+15, }
请问这个如何解决?

@andot
Copy link
Member

andot commented Mar 9, 2023

原数据来自哪儿?php 的数据的话,你可以用 int(1870381757955251) 来让原数据确定是个整数类型,如果你的原数据是来自 json 的话,那是 json 本身的问题,json 本身不区分整数和浮点数,解析的时候,对于比较大的整数会按照浮点数处理。

@chenxi2015
Copy link
Author

原数据来自哪儿?php 的数据的话,你可以用 int(1870381757955251) 来让原数据确定是个整数类型,如果你的原数据是来自 json 的话,那是 json 本身的问题,json 本身不区分整数和浮点数,解析的时候,对于比较大的整数会按照浮点数处理。

源数据来自于饿了么的消息推送过来的json字符串 然后获取这个数据进行rpc处理 源数据大概是:
{ "ticket": "771D9C38-4476******A920E48E8408", "encrypt": "", "sign": "A3E99F51778E9********82A881708C60", "cmd": "order.user.cancel", "source": "60981", "body": "{\"platform_shop_id\":\"422*****536\",\"reason_code\":\"7006\",\"cancel_reason\":\"\买\错\了\\/\买\少\了\",\"addition_reason\":\"\",\"refund_order_id\":1862138894955251,\"refuse_reason\":\"\",\"reason_code_desc\":\"\买\错\了\\/\买\少\了\",\"cancel_type\":\"1\",\"type\":\"10\",\"order_id\":\"40515201******677336\",\"pictures\":[],\"is_return_goods\":0}", "version": 3, "timestamp": 1678258235 }
我获取json中body的数据 json_decode 在请求rpc,refund_order_id这个数据就变成了科学计数法
难道需要我这边单独对这个字段进行处理吗?

@andot
Copy link
Member

andot commented Mar 15, 2023

这个是 json_decode 本身解码的问题,json_decode 解码之后的 refund_order_id 已经变成了一个 float 字段,而不是 int 字段,跟 hprose 没关系。

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

No branches or pull requests

2 participants