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.
Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
What is JsonResult ? JsonResult is one of the type of MVC action result type which returns the data back to the view or the browser in the form of JSON (JavaScript Object notation format).
JSONObject json= (JSONObject) JSONValue. parse(jsonData); JSONObject data = (JSONObject) json. get("data"); After you have parsed the json data, you need to access the data object later get "map" data to json string.
Below is a JSON string. To access the JSON object in JavaScript, parse it with JSON. parse() , and access it via “.” or “[]”.
You're looking for the JavaScriptSerializer
class, which is used internally by JsonResult:
string json = new JavaScriptSerializer().Serialize(jsonResult.Data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With