Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft Object → Get JSON string

Tags:

json

json.net

I have an object that is created by Newtonsoft's JSON serializer. I need to get the JSON string that was used to create the object. How do I serialize the object into a simple JSON string?

like image 807
Ian Vink Avatar asked Jul 14 '11 08:07

Ian Vink


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); The result will be a string following the JSON notation.

How do I deserialize a string in C#?

Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method. For the generic overloads, you pass the type of the class you created as the generic type parameter. For the non-generic overloads, you pass the type of the class you created as a method parameter.

How do I deserialize a JSON object?

We can implement JSON Serialization/Deserialization in the following three ways: Using JavaScriptSerializer class. Using DataContractJsonSerializer class. Using JSON.NET library.


1 Answers

Try this:

public string jsonOut() {     // Returns JSON string.     return JsonConvert.SerializeObject(this);        } 
like image 102
Sheena Avatar answered Oct 04 '22 12:10

Sheena