Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

json serialization

"if youre using System.Text.Json extention"
1. Serialize allows you to convert objects to a json format string:

string defaultPerson = JsonSerializer.Serialize(new Person{
  age = 28,
  nationality = "scottish"
  }) 
  
2. Deserialize allows you to convert json format string to an object:
   ScottishPerson = JsonSerializer.Deserialize<Person>(defaultPerson); 
Comment

serialize object to json

Product product = new Product();
product.ExpiryDate = new DateTime(2008, 12, 28);

JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Ignore;

using (StreamWriter sw = new StreamWriter(@"c:json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
    serializer.Serialize(writer, product);
    // {"ExpiryDate":new Date(1230375600000),"Price":0}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: linq to json 
Csharp :: Get Last Access Time Of Directory C# 
Csharp :: string substring c# before 
Csharp :: initialize a char array java 
Csharp :: if statement 
Csharp :: c# substring until character single 
Csharp :: in c sharp how do you work the wait function 
Csharp :: on collision unity 
Csharp :: C# Switch and case 
Csharp :: c# string methods 
Csharp :: ihttpactionresult to object c# 
Csharp :: what is list in c# 
Csharp :: Commenting on C# 
Csharp :: c# get set 
Csharp :: c# get all letters 
Csharp :: delete all rows from table linq 
Csharp :: c# get random index from list 
Csharp :: how to use double in c# 
Csharp :: freeze scene unity 
Csharp :: c# check if object is of any generic type 
Csharp :: how to sign in with your unity id in unity hub 
Csharp :: c# get random between 0 and 1 
Csharp :: aspx receive variable from url 
Csharp :: c# minimise form 
Csharp :: How to make enemy shooting 
Csharp :: ontriggerenter2d 
Csharp :: how to pause a console.writeline in C# 
Csharp :: unity deactivate scripts in list 
Csharp :: c# lambda group by multiple columns 
Csharp :: count number of rows in a table in c# 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =