title: How to send list of model objects in json format to API in flutter
body: <p>I am working on a Food Delivery App in <strong>Flutter</strong> and I have a list of model objects in my cart System. I need to send this list to API in JSON format so I convert that to JSON before sending it to server but i am getting error:</p>
  <p>errors: {: [Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Metronic.Models.FoodOrderInsert' because the type requires a JSON object (e.g. {&quot;name&quot;:&quot;value&quot;}) to deserialize correctly.</p>
  <p>I am beginner in Flutter and your kind response will highly be appreciated.
  I am currently converting list and sending it to API like this:
  I have my List of modelbjects:</p>
  <pre><code>List&lt;FoodDetail&gt; foodOrderDetails = [...]
  var jsonObjectsList = [];
  //Here I convert my list of FoodDetails into list of jsonObjects
  for (var item in foodOrderDetail) {
    jsonObjectsList.add(item.toJson());
  }
  await http
      .post(
    Uri.parse(url),
    headers: ApiURLs.header,
  
    body: jsonEncode(jsonObjectsList)
  )
  </code></pre>
  <p>And my API required data is:</p>
  <pre><code>[{
  &quot;OrderId&quot;: 0,
  &quot;ProductId&quot;: 0,
  &quot;Quantity&quot;: 0,
  &quot;Price&quot;: 0}]
  </code></pre>
  <p>my FoodDetail class contain same these properties and converted to json but the problem I think is in conveting whole list to json.</p>