コード例 #1
0
ファイル: Program.cs プロジェクト: UladzislauHlebau/my_repo
        public static void DeserializeFromJSON()
        {
            string exampleJson = "{\"Id\":01,\"Name\":\"Olivie\",\"CalorificValue\":\"400\",\"Price\": 1500}";
            //Deserialize json string to SaladJSON class
            SaladJSON saladJSON = JsonConvert.DeserializeObject <SaladJSON>(exampleJson);

            //Display deserialized Customer
            Console.WriteLine(saladJSON);
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: UladzislauHlebau/my_repo
        private static void WriteToJSONUsingSerialization()
        {
            SaladJSON saladJSON = new SaladJSON();

            saladJSON.Id             = 01;
            saladJSON.Name           = "Oliv'e";
            saladJSON.CalorificValue = 600;
            saladJSON.Price          = 120.5;

            //Serialize an object to Json
            string actualJson = JsonConvert.SerializeObject(saladJSON);

            //Display serialized to json saladJSON
            Console.WriteLine(actualJson);
            Console.ReadLine();
        }