19 September 2016

C# - Convert JSON string to JSON HttpResponseMessage

Use following method/function to convert string having JSON data to JSON HttpResponseMessage -

public static HttpResponseMessage CreateJsonResponse(string json)
{
    return new HttpResponseMessage()
    {
        Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json")
    };

}

Following code can be used to call this method/function

var response = CreateJsonResponse(jSonString);

Following code can be used to call this method/function

2 comments:

Unknown said...

Thank you so much

Unknown said...

Console.WriteLine("HTTP Response: " + responseString + "\n");
RestResponse restResponse = null;
if (acceptJSON)