728x90
반응형
https://www.sololearn.com/compiler-playground/c5Dt36lP1AHN/
를 참조하였습니다.
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
반응형
'프로그램언어 C C++' 카테고리의 다른 글
편미분 연쇄법칙 확장 (0) | 2023.05.23 |
---|---|
Dot Product of Matrix (0) | 2023.05.23 |
NumPy - 파이썬 라이브러리( C 코드, 수행속도, 다차원/배열 처리) (0) | 2023.04.16 |
[Selenium] WebDriver 사용-C# 샘플 프로그램 (0) | 2023.04.07 |
멀티바이트 vs. 유니코드 (0) | 2023.01.30 |