C# JSON String to Web API
<p>Currently facing an issue when making a JSON string in C# and trying to send it through to a web API using the WebClient.</p>

<p>Currently I have a few methods, first off the one that works. Using POSTMAN sending the following dataset of text through to the API works correctly:</p>

<blockquote>
  <p>POSTMAN Dataset - This Works in POSTMAN</p>
</blockquote>

<pre><code>{ "record": 
    {
        "form_id": "efe4f66f-b57c-4497-a370-25c0f3d8746a",
        "status": "240",
        "latitude": -82.638039,
        "longitude": 27.770787,
        "form_values": 
        {
            "833b": "99999",
            "683b": "9999999",
            "fa37": "Testing",
            "b2e3": "Testing"
        }
    }
}
</code></pre>

<p>In C# I am using a few different ways to construct this sting with little success.</p>

<blockquote>
  <p>C# List Method - Newtonsoft.Json.Serialization</p>
</blockquote>

<p>The first is building a List and then using Newtonsoft.Json to play with it:</p>

<pre><code>    List&lt;Parent&gt; DataList = new List&lt;Parent&gt;();
    List&lt;Child&gt; Form = new List&lt;Child.formvalues&gt;();
    var Formvals = new Child.formvalues
    {
        ActionDescription = Row.ActionDescription,
        ActionNotes = Row.ActionNotes,
        ActionID = Row.ActionID,
        AssetID = Row.AssetID
    };
    Form.Add(Formvals);

    var DataElement = new Parent
    {
        form_id = AppFormID,
        latitude = Lat,
        longitude = Long,
        status = Row.Status,
        form_values = Form
    };
    DataList.Add(DataElement);

    string json = JsonConvert.SerializeObject(DataList.ToArray());
</code></pre>

<p>This code results in the following string:</p>

<pre><code>[
    {\"form_id\":\"efe4f66f-b57c-4497-a370-25c0f3d8746a\",
    \"latitude\":-82.638039,
    \"longitude\":27.770787,
    \"status\":239,
    \"form_values\":[
        {\"833b\":99999,
        \"683b\":9999999,
        \"fa37\":\"Testing\",
        \"b2e3\":\"Testing\"
        }]
    }
]
</code></pre>

<p>Another attempt I am trying is the following, which in my opinion is the closest so far:</p>

<blockquote>
  <p>C# - String Building Method</p>
</blockquote>

<pre><code>string Content = @"{ "
       + "\"record\": {"
       + "\"form_id\": "\"" + AppFormID + ""\","
       + "\"status\": "\"" + Row.Status + ""\","
       + "\"latitude\": "+ Lat  + ","
       + "\"longitude\": "+ Long + ","
       + "\"form_values\": {"
            + "\"833b\": "\""+Row.AssetID +""\","
            + "\"683b\": "\""+Row.ActionID + ""\","
            + "\"fa37\": "\""+Row.ActionDescription + ""\","
            + "\"b2e3\": "\""+Row.ActionNotes + ""\""
        + "}"
       + "}"
      + "}";
</code></pre>

<p>That line results in:</p>

<pre><code>{ \"record\": 
    {
        \"form_id\": \"efe4f66f-b57c-4497-a370-25c0f3d8746a\",
        \"status\": \"239\",
        \"latitude\": -82.638039,
        \"longitude\": 27.770787,
        \"form_values\": 
        {
            \"833b\": \"99999\",
            \"683b\": \"9999999\",
            \"fa37\": \"Testing\",
            \"b2e3\": \"Testing\"
        }
  }
}
</code></pre>

<blockquote>
  <p>The Question!</p>
</blockquote>

<p>So the question, is someone able to help me achieving the format in the first JSON that I put into POSTMAN exactly?</p>

<blockquote>
  <p>UPDATE - 6:40PM</p>
</blockquote>

<p>Web client code c#
AppURLRef is set in code further up and appears to be correct in the debugger. json is the result of the tests.</p>

<pre><code>var http = new WebClient();
http.Headers.Add(HttpRequestHeader.ContentType, "application/json");
var response = http.UploadString(AppURLRef, "POST", json);
</code></pre>

<blockquote>
  <p>Result of Update</p>
</blockquote>

<pre><code>"[{\"record\":{\"form_id\":\"efe4f66f-b57c-4497-a370-25c0f3d8746a\",
\"latitude\":-82.638039,
\"longitude\":27.770787,
\"status\":\"240\",
\"form_values\":         
[{\"833b\":\"99999\",
\"683b\":\"9999999\",
\"fa37\":\"Testing\",
\"b2e3\":\"Testing\"}]}}]"
</code></pre>