Namespace Newtonsoft.Json.Formatting Newtonsoft.Json.Formatting ব্যবহার করুন Json ফর্ম্যাট করার জন্য ফর্ম্যাটিং বিকল্পগুলি প্রদান করে
কোনটিই নয়৷ - কোন বিশেষ বিন্যাস প্রয়োগ করা হয় না। এটি ডিফল্ট৷
ইন্ডেন্টেড৷ − Newtonsoft.Json.JsonTextWriter.Indentation এবং Newtonsoft.Json.JsonTextWriter.IndentChar সেটিংস অনুসারে চাইল্ড অবজেক্টগুলিকে ইন্ডেন্ট করা হয়৷
উদাহরণ
static void Main(string[] args){
Product product = new Product{
Name = "Apple",
Expiry = new DateTime(2008, 12, 28),
Price = 3.9900M,
Sizes = new[] { "Small", "Medium", "Large" }
};
string json = JsonConvert.SerializeObject(product, Formatting.Indented);
Console.WriteLine(json);
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
Console.ReadLine();
}
class Product{
public String[] Sizes { get; set; }
public decimal Price { get; set; }
public DateTime Expiry { get; set; }
public string Name { get; set; }
} আউটপুট
{
"Sizes": [
"Small",
"Medium",
"Large"
],
"Price": 3.9900,
"Expiry": "2008-12-28T00:00:00",
"Name": "Apple"
} উদাহরণ
static class Program{
static void Main(string[] args){
Product product = new Product{
Name = "Apple",
Expiry = new DateTime(2008, 12, 28),
Price = 3.9900M,
Sizes = new[] { "Small", "Medium", "Large" }
};
string json = JsonConvert.SerializeObject(product, Formatting.None);
Console.WriteLine(json);
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
Console.ReadLine();
}
}
class Product{
public String[] Sizes { get; set; }
public decimal Price { get; set; }
public DateTime Expiry { get; set; }
public string Name { get; set; }
} আউটপুট
{"Sizes":["Small","Medium","Large"],"Price":3.9900,"Expiry":"2008-12-28T00:00:00","Name":"Apple"}