728x90
반응형

https://www.sololearn.com/compiler-playground/c5Dt36lP1AHN/

 

https://www.sololearn.com/compiler-playground/c5Dt36lP1AHN/

 

www.sololearn.com

를 참조하였습니다.
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;


namespace ExampleApplication
{
    public class Person
    {
        public int PersonID { get; set; }
        public string Name{ get; set; }
        public bool Registered{ get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine ("Hello World");
                       
            var RegisteredUsers = new List<Person>();
            RegisteredUsers.Add( new Person () {  PersonID=1, Name="Bryon Hetrik", Registered = true  });
            RegisteredUsers.Add( new Person () {  PersonID=2, Name="Nicole Wilcox", Registered = true  });
            RegisteredUsers.Add( new Person () {  PersonID=3, Name="Adrian Martinson", Registered = false  });
            RegisteredUsers.Add( new Person () {  PersonID=4, Name="Nora Osborn", Registered = false  });
           

            var serializer = new JavaScriptSerializer();
            var serializedResult = serializer.Serialize(RegisteredUsers);            
            Console.WriteLine( serializedResult );

            var deserializedResult = serializer.Deserialize<List<Person>>( serializedResult );
            //var deserializedResult = serializer.Deserialize< List <object>>( serializedResult );

            Console.WriteLine(deserializedResult.Count );            
            

foreach ( var item in deserializedResult ){
                Console.WriteLine($"{item.PersonID}");
                Console.WriteLine($"{item.Name}");            
            }
           
            Console.WriteLine("Done!");

            var cities = new Dictionary<string, object>() {
                {"UK", "London, Manchester, Birmingham"},
                {"USA", "Chicago, New York, Washington"},
                {"India", "Mumbai, New Delhi, Pune"},
                {"Available", false }
            };

            foreach( var city in cities ){
                Console.WriteLine(" Key : {0}, Value: {1}", city.Key, city.Value );
            }

            //use ContainsKey() to check for an unknown key
            if( cities.ContainsKey("India")) {
                Console.WriteLine( cities["India"]);
            }

            //use TryGetValue() to get a value of unknown key            
            if( cities.TryGetValue("Available", out object result )){
                Console.WriteLine( (bool) result);

            }


            //var Profiles = serializer.Deserialize<List<object>>( profilesResponse );
            //Console.WriteLine( Profiles.Count );






         
            Console.WriteLine("!!!!DONE");
        }
    }
}

 

 

출력 결과 

 

 

Hello World
[{"PersonID":1,"Name":"Bryon Hetrik","Registered":true},{"PersonID":2,"Name":"Nicole Wilcox","Registered":true},{"PersonID":3,"Name":"Adrian Martinson","Registered":false},{"PersonID":4,"Name":"Nora Osborn","Registered":false}]
4
1
Bryon Hetrik
2
Nicole Wilcox
3
Adrian Martinson
4
Nora Osborn
Done!
Key : UK, Value: London, Manchester, Birmingham
Key : USA, Value: Chicago, New York, Washington
Key : India, Value: Mumbai, New Delhi, Pune
Key : Available, Value: False
Mumbai, New Delhi, Pune
False
!!!!DONE

 

728x90
반응형

+ Recent posts