1 //Create my object
2 var my_jsondata = new
3 {
4 Host = @"sftp.myhost.gr",
5 UserName = "my_username",
6 Password = "my_password",
7 SourceDir = "/export/zip/mypath/",
8 FileName = "my_file.zip"
9 };
10
11 //Tranform it to Json object
12 string json_data = JsonConvert.SerializeObject(my_jsondata);
13
14 //Print the Json object
15 Console.WriteLine(json_data);
16
17 //Parse the json object
18 JObject json_object = JObject.Parse(json_data);
19
20 //Print the parsed Json object
21 Console.WriteLine((string)json_object["Host"]);
22 Console.WriteLine((string)json_object["UserName"]);
23 Console.WriteLine((string)json_object["Password"]);
24 Console.WriteLine((string)json_object["SourceDir"]);
25 Console.WriteLine((string)json_object["FileName"]);
26
1//open file stream
2using (StreamWriter file = File.CreateText(@"D:\path.txt"))
3{
4 JsonSerializer serializer = new JsonSerializer();
5 //serialize object directly into file stream
6 serializer.Serialize(file, _data);
7}
1dynamic ret = new JObject();
2
3ret = new JObject(new JProperty("vendorDetails", new JObject()));
4
5ret.vendorDetails.Add(new JProperty("vendorName", "Vendor Name"));