|
Post by dejohnny on Apr 7, 2022 20:23:14 GMT -5
How to parse the data in a Json object using Newtonsoft JObject.
using Newtonsoft.Json.Linq;
// Simple Json string json = @"{ CPU: 'Intel', Drives: [ 'DVD read/writer', '500 gigabyte hard drive' ] }";
// Parse and store as a C# object JObject o = JObject.Parse(json);
// More complex Json structure
JObject o1 = JObject.Parse(@"{ 'CPU': 'Intel', 'Drives': [ 'DVD read/writer', '500 gigabyte hard drive' ] }");
string cpu = (string)o1["CPU"]; // Intel
string firstDrive = (string)o1["Drives"][0]; // DVD read/writer
IList<string> allDrives = o1["Drives"].Select(t => (string)t).ToList(); // DVD read/writer // 500 gigabyte hard drive
|
|