1// read file into a string and deserialize JSON to a type
2Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));
3
4// deserialize JSON directly from a file
5using (StreamReader file = File.OpenText(@"c:\movie.json"))
6{
7 JsonSerializer serializer = new JsonSerializer();
8 Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
9}
1JObject o1 = JObject.Parse(File.ReadAllText(@"c:\videogames.json"));
2
3// read JSON directly from a file
4using (StreamReader file = File.OpenText(@"c:\videogames.json"))
5using (JsonTextReader reader = new JsonTextReader(file))
6{
7 JObject o2 = (JObject)JToken.ReadFrom(reader);
8}
1
2//For any of the JSON parse, use the website
3//http://json2csharp.com/
4//(easiest way) to convert your JSON into
5//C# class to deserialize your JSON into C# object.
6
7public class FormatClass
8{
9 public string JsonName { get; set; }
10 public string JsonPass { get; set; }
11}
12//Then use the JavaScriptSerializer (from System.Web.Script.Serialization),
13// in case you don't want any third party DLL like newtonsoft.
14public void Read()
15{
16 using (StreamReader Filejosn = new StreamReader("Path.json"))
17 {
18 JavaScriptSerializer jss = new JavaScriptSerializer();
19 var Items = jss.Deserialize<FormatClass>(Filejosn.ReadToEnd());
20 // Add Code here :)
21 }
22}
23//by ahmed ashraf +201111490105
24