search

Home  >  Q&A  >  body text

php - After JSON data is formatted, the data order changes

{"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"}

The above is the raw data of JSON.
I requested it using postman, and then after formatting I found that the order of the array had changed. Because I was dealing with an array sorting problem, I checked the code for a long time and found that there was no problem. Then I found that the formatting was wrong. May I ask what might be the reason for this?
The following is a formatted screenshot. Obviously the first value in the source code is 171865304

曾经蜡笔没有小新曾经蜡笔没有小新2704 days ago1018

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-07-01 09:13:58

    Because this is an object, and the object is full of key-value pairs, and the order is random. The specific order is determined by the browser itself. If you want order, it is recommended to turn this type of object into an array in the following format:

    [
        { .... },
        { .... },
        { .... },
        { .... }
    ]

    reply
    0
  • 天蓬老师

    天蓬老师2017-07-01 09:13:58

    Because your Orders is an object, not an array

    reply
    0
  • Cancelreply