C# Write Json file error -


i want write data object json file.

my class person

public class person {     private string firstname;     private string lastname;     private int height;     private double weight;      public person() { }     public person(string firstname, string lastname, int height, double weight)     {         this.firstname = firstname;         this.lastname = lastname;         this.height = height;         this.weight = weight;     } } 

my program class

class program {     static void main(string[] args)     {         // serialize json string , write string file         person ps1 = new person("tay", "son", 180, 99.99);         string json = jsonconvert.serializeobject(ps1,formatting.indented);         file.writealltext(@"c:\person.json", json);         console.writeline("done");         console.readline();     } } 

person.json displays: "{}"

please helps me fix error.

change code to:

public string firstname; public string lastname; public int height; public double weight; 

private fields aren't serialised.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -