Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONResult to String

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.

like image 247
Dustin Laine Avatar asked Dec 31 '10 19:12

Dustin Laine


People also ask

How can I convert JSON to string?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);

What is JsonResult type in MVC?

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).

How do you pass a JSON object into a string in Java?

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.

How do I access JsonResult?

Below is a JSON string. To access the JSON object in JavaScript, parse it with JSON. parse() , and access it via “.” or “[]”.


1 Answers

You're looking for the JavaScriptSerializer class, which is used internally by JsonResult:

string json = new JavaScriptSerializer().Serialize(jsonResult.Data); 
like image 122
SLaks Avatar answered Sep 29 '22 16:09

SLaks