简体   繁体   中英

How do I create a list in JSON equivalent to a list on Kotlin?

I'm learning Ktor and trying to test a POST request implementation I made using the example model given here . However, I have no idea how to make a proper list in JSON that Ktor could read and deserialize as a list.

I've tried:

{
  "number": "2022-04-28",
  "contents": {
    "OrderItem": {
      "item": "Tea",
      "amount": 5,
      "price": 2.99
    },
    "OrderItem": {
      "item": "Coffee",
      "amount": 2,
      "price": 4.99
    }
  }
}

But I get an internal server error whenever I try to send the POST request.

contents should be a list [] of objects

{
  "number": "2022-04-28",
  "contents": [
    {
      "item": "Tea",
      "amount": 5,
      "price": 2.99
    },
    {
      "item": "Coffee",
      "amount": 2,
      "price": 4.99
    }
  ]
}

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