简体   繁体   中英

http post request change the order of json object in ios (ionic 3)

I am working on an ionic app which will be used on android and iOS platforms.and I need to post an object to the server which contain some attribute that reference others for example:

{
"room": [
 {
   "@id": 2,
   "date": "2019-10-10",
   "number": "750"
 }
],
"bed": [
[
  {
    "class": "A",
    "room": 2
  }
 ]
]
}

but when posting it the order of the JSON object changes to :

{
"bed": [
 [
   {
     "class": "A",
     "room": 2
   }
 ]
],
"room": [
  {
    "@id": 2,
    "date": "2019-10-10",
    "number": "750"
  }
 ]
 }

what should I do to keep the order of the object, considering that it works fine in android?

Referring to JSON's standards , an object is simply unordered which means there is no problem with your case. However, if in your case the order is important, you may use arrays. Arrays make sure the order is preserved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM