For example, there is a simple class

class Point { public int X { get; set; } public int Y { get; set; } } 

How to translate the contents of this class into an equivalent entry in JSON? The search tells you about the JSON.NET library, is there a solution based on the built-in language tools (in particular for the Compact Framework)?

    2 answers 2

    View the built-in JavaScriptSerializer

     public class Student { public string Name { get; set; } public string Age { get; set; } public string AverageRating { get; set; } } List<Student> students = new List<Student>(); JavaScriptSerializer serializer = JavaScriptSerializer(); string json = serializer.Serialize(students); 

      Class for serialization:

       [Serializable] public class Data { public string Value; } 

      And surgery on it

       DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(Data)); using (FileStream fs = File.OpenRead(filename) { Data data = s.ReadObject(fs) as Data; }