title: Receive RESTClient POST JSON-Body in C# mvc and convert it to usable Data
body: <p>I have a C# Website and Web API combined and a Mobile Android App. In the Mobile Android App I want to send a HttpPost with an <code>List&lt;Integer&gt;</code>, <code>List&lt;Double&gt;</code> and <code>long</code> to the C# Web API and in the C# Web API I want to convert those back to <code>List&lt;int&gt;</code>, <code>List&lt;decimal&gt;</code> and <code>long</code>.</p>
  
  <p>The sending part from the Android App was done quite fast, since I've done this before. But at the receiving C# Web API end I'm having (a lot) of trouble.</p>
  
  <p>In one of the Web API Controllers I've added the following method:</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ActionName("save")]
  public bool SaveOrders([FromBody] STILL_UNDETERMINED parameter)
  {
      // TODO: Convert given parameter to usable List&lt;int&gt;, List&lt;decimal&gt; and long
  }
  </code></pre>
  
  <p>Right now I'm using the FireFox' RESTClient Plug-in to send these HttpPOSTs:</p>
  
  <pre><code>Method:   POST   http://localhost:54408/api/orders/save
  Header:   Content-Type   application/x-www-form-urlencoded
  Body:     {"newPrices":[0.4,7.4],"productIds":[20,25],"dateInTicks":1402459200000}
  </code></pre>
  
  <p>I do end up in the method above and can debug it, but now I need to convert it to the List, List and long.</p>
  
  <p>So, my question(s):</p>
  
  <p><strong>What parameter should I use for the method?</strong> I've tried:</p>
  
  <ul>
  <li><code>string</code> (which is always null);</li>
  <li><code>JObject</code> (which replaces all <code>[</code> for <code>:" {"</code> for some unknown reason, resulting in: <code>{ "{\"newPrices\":": { "0.4,7.4],\"productIds\":": { "20,25],\"dateInTicks\":1402459200000}": "" } } }</code>;</li>
  <li>and <code>dynamic</code> (which I can't do anything with since it's converter to an seemingly empty <code>object</code>)</li>
  </ul>
  
  <p><strong>How should I convert this parameter to a <code>List&lt;int&gt;</code>, <code>List&lt;decimal&gt;</code> and <code>long</code>?</strong></p>
  
  <ul>
  <li>I've tried creating an custom Object (see below) and use all kind of different method to fill them, to many to list all here, all without a result (mainly because the parameter is already wrong):</li>
  </ul>
  
  <p>Custom Object:</p>
  
  <pre><code>Data
  {
         public List&lt;int&gt; productIds { get; set; }
         public List&lt;decimal&gt; newPrices { get; set; }
         public long dateInTicks { get; set; }
  }
  </code></pre>
  
  <p>In theory it seems so simple:</p>
  
  <ul>
  <li>Send a HttpPOST from the FireFox' RESTClient plug-in</li>
  <li>Have a method in the API Controller that receives it (this already took quite some time and had to make some changes to MapHttpRoutes by using <code>actions</code>).</li>
  <li>Convert the paramater you receive from the Body to usable data (the part I'm stuck on right now..)</li>
  </ul>
  
  <p>It seemed so simple, yet I can't get it to work in C#.. In Java I would have made this in less than 30 min and I can find a lot useful answers by Google-ing, but when I Google for C# HttpPOSTs I only get results to either send HttpPOSTs from C#, or read the response from the Stream AFTER sending the HttpPOST.. Nothing about just receiving JSON-body of a HttpPOST from a <code>[HttpPost]</code> method in C# mvc..</p>
  
  <p>PS: I have the following in my Config file to only receive JSON format responses, maybe something is wrong with that.</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);
  </code></pre>