Quantcast
Channel: How can I deserialize JSON to a simple Dictionary in ASP.NET? - Stack Overflow
Viewing all articles
Browse latest Browse all 23

Answer by wdanxna for How can I deserialize JSON to a simple Dictionary in ASP.NET?

$
0
0

For anyone who is trying to convert JSON to dictionary just for retrieving some value out of it. There is a simple way using Newtonsoft.JSON

using Newtonsoft.Json.Linq...JObject o = JObject.Parse(@"{'CPU': 'Intel','Drives': ['DVD read/writer','500 gigabyte hard drive'  ]}");string cpu = (string)o["CPU"];// Intelstring firstDrive = (string)o["Drives"][0];// DVD read/writerIList<string> allDrives = o["Drives"].Select(t => (string)t).ToList();// DVD read/writer// 500 gigabyte hard drive

Viewing all articles
Browse latest Browse all 23

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>