I have a JsonResult
that is working fine, and returning JSON from some POCO's. I want to save the JSON as a string in a DB.
public JsonResult GetJSON()
{
JsonResult json = new JsonResult
{
Data = GetSomPocos()
};
return json;
}
I need to audit the response, so I want to save the json
into a DB. I am having trouble finding a way to get the JSON as a string.
Any help is appreciated.
This question is related to
c#
json
asp.net-mvc-2
serialization
json = " { \"success\" : false, \"errors\": { \"text\" : \"??????!\" } }";
return new MemoryStream(Encoding.UTF8.GetBytes(json));
You can also use Json.NET.
return JsonConvert.SerializeObject(jsonResult.Data);
Source: Stackoverflow.com