title: JSON body to List<int>, List<decimal> and long
body: <p>I have a C# Website and Web API combined with a Save-method in one of my API Controllers. This method only allows HttpPosts. What I want to send in the body is a <code>List&lt;int&gt;</code>, <code>List&lt;decimal&gt;</code> and <code>long</code>. </p>
  
  <p>Since HttpPost methods in API Controllers only allow one parameter to work, I tried both a <code>JObject</code> and <code>string</code> as parameter. When I use string it's always null, when I use JObject it's not null but incorrectly copied from the body. Because these are null and incorrectly copied, the converting to the <code>List&lt;int&gt;</code>, <code>List&lt;decimal&gt;</code> and <code>long</code> are also not working.</p>
  
  <hr>
  
  <p>Parameter as string:</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ActionName("save")]
  public bool SaveOrders([FromBody] string jsonData)
  {
      // Convert jsonData string to List&lt;int&gt;, List&lt;decimal&gt;, long
      JObject json = JObject.Parse(jsonData);
      List&lt;int&gt; productIds = JsonConvert.DeserializeObject(json["productIds"].ToString(), typeof(List&lt;int&gt;));
      List&lt;decimal&gt; prices = JsonConvert.DeserializeObject(json["prices"].ToString(), typeof(List&lt;decimal&gt;));
      long dateInTicks = JsonConvert.DeserializeObject(json["dateInTicks"].ToString(), typeof(long));
  
      ...
  }
  </code></pre>
  
  <p>with POST-body:</p>
  
  <pre><code>"{
      "productIds": "[20, 25]",
      "prices": "[0.40, 7.40]",
      "dateInTicks": "1402444800"
  }"
  </code></pre>
  
  <p>When I debug this above, the parameter-string is always null.</p>
  
  <hr>
  
  <p>Parameter as JObject:</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ActionName("save")]
  public bool SaveOrders([FromBody] JObject jsonData)
  {
      // Convert jsonData JObject to List&lt;int&gt;, List&lt;decimal&gt;, long
      dynamic json = jsonData;
      string sProductIds = (string)json["productIds"];
      string sPrices = (string)json["prices"];
      string sDateInTicks = (string)json["dateInTicks"];
      List&lt;int&gt; productIds = JsonConvert.DeserializeObject(sProductIds, typeof(List&lt;int&gt;));
      List&lt;decimal&gt; prices = JsonConvert.DeserializeObject(sPrices, typeof(List&lt;decimal&gt;));
      long dateInTicks = JsonConvert.DeserializeObject(sDateInTicks, typeof(long));
  
      ...
  }
  </code></pre>
  
  <p>with POST-body:</p>
  
  <pre><code>productIds: "[20, 25]",
  prices: "[0.40, 7.40]",
  dateInTicks: "1402444800"
  </code></pre>
  
  <p>When I debug this, the parameter-JObject is:</p>
  
  <pre><code>{
    "productIds: \"": {
      "20, 25]\",\nprices: \"": {
        "0.40, 7.40]\",\ndateInTicks: \"1402444800\"": ""
      }
    }
  }
  </code></pre>
  
  <p>and the sProductIds, sPrices and sDateInTicks are null.</p>
  
  <hr>
  
  <p>I know I'm doing some things wrong, therefore this question, since I don't how I should change it.</p>
  
  <hr>
  
  <p>Edit 1 (Rafal's suggestion):</p>
  
  <p>In my config file I added one line:</p>
  
  <pre><code>// Only allow JSON response format
  var json = config.Formatters.JsonFormatter;
  json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
  config.Formatters.Remove(config.Formatters.XmlFormatter);
  // Added the following line:
  config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
  </code></pre>
  
  <p>And my method is changed:</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ActionName("save")]
  public bool SaveOrders([FromBody] Data jsonData)
  {
      if (jsonData != null)
      {
          if (jsonData.productIds != null &amp;&amp; jsonData.prices != null)
          {
              return SavePrices(jsonData.productIds, jsonData.prices, jsonData.dateInTicks);
          }
          else
          {
              Console.WriteLine("One of the objects is null, so we can't continue.");
              return false;
          }
      }
      else
      {
          Console.WriteLine("The send data is null, so we can't continue.");
          return false;
      }
  }
  
  public class Data
  {
      public List&lt;int&gt; productIds { get; set; }
      public List&lt;decimal&gt; prices { get; set; }
      public long dateInTicks { get; set; }
  }
  </code></pre>
  
  <p>But although the Data-parameter isn't null, both the Lists inside of it are and the long is 0 as well.</p>
  
  <hr>
  
  <p>Edit 2:</p>
  
  <p>With the FireFox' RESTClient Body:</p>
  
  <pre><code>"productIds":[20,25],"prices":[0.4,7.4],"dateInTicks":1402444800
  </code></pre>
  
  <p>Why is the JObject parameter this:</p>
  
  <pre><code>{
    "\"productIds\":": {
      "20,25],\"prices\":": {
        "0.4,7.4],\"dateInTicks\":1402444800": ""
      }
    }
  }
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>{
    \"productIds\":[20,25],\"prices\":[0.4,7.4],\"dateInTicks\":1402444800
  }
  </code></pre>
  
  <p>It automatically removes the first <code>[</code> with the arrays and replaces it with <code>:" {"</code>..</p>