JSON数据格式化以后,数据顺序发生了改变

发布于 2022-09-05 03:21:30 字数 2704 浏览 15 评论 0

{"Code":"0","Result":{"Orders":{"171865304":{"LastId":30351,"Time":"2017-06-28T14:56:28+08:00","OrderId":171865304,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1326","OriginStatus":"D"},"171865316":{"LastId":30360,"Time":"2017-06-28T15:02:20+08:00","OrderId":171865316,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1327","OriginStatus":"D"},"171865325":{"LastId":30361,"Time":"2017-06-28T15:05:05+08:00","OrderId":171865325,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1328","OriginStatus":"D"},"171865326":{"LastId":30362,"Time":"2017-06-28T15:05:59+08:00","OrderId":171865326,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1329","OriginStatus":"D"},"171865327":{"LastId":30363,"Time":"2017-06-28T15:11:32+08:00","OrderId":171865327,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1330","OriginStatus":"D"},"171865294":{"LastId":30378,"Time":"2017-06-28T15:37:05+08:00","OrderId":171865294,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-06-28T00:00:00+08:00","DepartureDate":"2017-06-29T00:00:00+08:00","TotalPrice":70,"NumberOfRooms":1,"AffiliateConfirmationId":"314243799193660","OriginStatus":"D"},"171865125":{"LastId":30440,"Time":"2017-06-28T16:57:08+08:00","OrderId":171865125,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-06T00:00:00+08:00","DepartureDate":"2017-07-07T00:00:00+08:00","TotalPrice":601,"NumberOfRooms":1,"AffiliateConfirmationId":"H170627110452902933","OriginStatus":"D"},"171865382":{"LastId":30485,"Time":"2017-06-28T18:26:32+08:00","OrderId":171865382,"Status":-6,"PayStatus":-1,"ArrivalDate":"2017-07-18T00:00:00+08:00","DepartureDate":"2017-07-19T00:00:00+08:00","TotalPrice":8,"NumberOfRooms":1,"AffiliateConfirmationId":"1331","OriginStatus":"D"}}},"Guid":"afcbafd4-0831-43bf-8daf-6a605f0fcc05"}

上面是JSON的raw数据。
我是用postman请求的,然后格式化以后发现数组的顺序发生了改变,因为我是处理一个数组的排序问题,检查了很久的代码发现没问题,然后发现是格式化出错了。请问一下这大概是什么原因导致的。
下面是经过格式化后的截图,明显源码里的第一个值是171865304

clipboard.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心作怪 2022-09-12 03:21:30

因为你这是一个对象,对象里都是键值对,顺序是随机的。具体的顺序如何是浏览器自己决定的。如果想要有序,建议将此类对象变为如下格式数组:

[
    { .... },
    { .... },
    { .... },
    { .... }
]
顾北清歌寒 2022-09-12 03:21:30

因为你的Orders是个对象,不是个数组啊

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文