I have a JSON string
{
"Date":"21/11/2010"
"name": "TEST"
"place":"xyz"
}
I want to convert it into a C# dictionary without using a third party library
Using JsonConverterJsonConvert class has a method to convert to and from JSON string, SerializeObject() and DeserializeObject() respectively. It can be used where we won't to convert to and from a JSON 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.
Use the JavaScriptSerializer class to provide serialization and deserialization functionality for AJAX-enabled ASP.NET web applications. The JavaScriptSerializer. Deserialize() method converts the specified JSON string to the type of the specified generic parameter object.
You can do it natively since net 3.5 with jsonserializer.
var jss = new JavaScriptSerializer();
var dict = jss.Deserialize<Dictionary<string,string>>(jsonText);
var place = dict["place"]; // "xyz"
Here is a simple tutorial for your case: Quick JSON Serialization/Deserialization in C#
Requires the System.Web.Extensions
reference. If you can't find it, your program is probably using a Client target framework. Use a "Full" target framework.
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