AddReference Add Reference

AddReference2System.Web.Extensions 추가


using System.Web.Script.Serialization;
// JSON serialize
JavaScriptSerializer serializer = new JavaScriptSerializer(new FigureTypeResolver());
var json = serializer.Serialize(figureList.ToArray());

// JSON deserialize
JavaScriptSerializer deserializer = new JavaScriptSerializer(new FigureTypeResolver());
var loadedFigureList = (List<Figure>)deserializer.Deserialize(json, figureList.GetType());

// convert every item to Figure
for (int i = 0; i < loadedFigureList.Count; i++)
var f = (Figure)loadedFigureList[i];
FigureType type = FigureCalculator.GetFigureType(f);
Console.WriteLine(FigureCalculator.Perimeter(type, f));
Console.WriteLine(FigureCalculator.Area(type, f));

Leave a Reply

Your email address will not be published. Required fields are marked *