IHttpActionResult with JSON string
<p>I have a method that originally returned an <code>HttpResponseMessage</code> and I'd like to convert this to return <code>IHttpActionResult</code>.</p>

<p>My problem is the current code is using JSON.Net to serialize a complex generic tree structure, which it does well using a custom <code>JsonConverter</code> I wrote (the code is working fine).</p>

<p>Here's what it returns:</p>

<pre><code>    string json = NodeToJson(personNode);

    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
    response.Content = new StringContent(json, Encoding.UTF8, "application/json");

    return response;
</code></pre>

<p>The NodeToJson method is where the custom converter comes into play ...</p>

<pre><code>private static string NodeToJson(Node&lt;Person&gt; personNode) {

    var settings = new JsonSerializerSettings {
        Converters = new List&lt;JsonConverter&gt; { new OrgChartConverter() },
        Formatting = Formatting.Indented
    };

    return JsonConvert.SerializeObject(personNode, settings);

}
</code></pre>

<p>Note this returns a <code>string</code>, formatted as JSON.</p>

<p>If I switch this to <code>IHttpActionResult</code>, it seems to fail regardless of what I try. I can just leave it (it works) but I am supposed to be using best practices for this and <code>IHttpActionResult</code> seems to be what I should be using.</p>

<p>I have tried to <code>return Json(json);</code> but this results in invalid, unparsable JSON, presumably because it's trying to do a double conversion?</p>

<p><code>return Ok(json);</code> results in the JSON string being wrapped in XML.</p>

<p>What is the right way to do this?</p>

<p><strong>EDIT:</strong></p>

<p>I have successfully converted every method in this project to use IHttpActionResult now except this particular method.</p>

<p>It's a serialization of a generic tree to JSON.  Regardless of what approach I try, I get back invalid JSON.  The <code>HttpResponseMsessage</code> approach works fine, but I can not get valid JSON back with <code>IHttpActionResult</code>.</p>