Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <Lizard> lizards = Lizard.GetLizards();

            //SerializaOneLizard("one.json", lizards[0]);
            //SerializeAllLizards("all.json", lizards);
            //DeserializaOneLizard("one.json");
            DeserializaAllLizards("all.json");
        }
Exemplo n.º 2
0
 static void DeserializaOneLizard(string filename)
 {
     using (TextReader reader = new StreamReader(filename))
     {
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         string input  = reader.ReadToEnd();
         Lizard lizard = serializer.Deserialize <Lizard>(input);
         Console.WriteLine(lizard);
     }
 }
Exemplo n.º 3
0
        static void SerializaOneLizard(string filename, Lizard lizard)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string output = serializer.Serialize(lizard);

            using (TextWriter writer = new StreamWriter(filename))
            {
                writer.Write(output);
            }
        }
Exemplo n.º 4
0
        static void SerializeOneLizard(string filename, Lizard lizard)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            using (TextWriter writer = new StreamWriter(filename))
            {
                string result = serializer.Serialize(lizard);
                writer.WriteLine(result);
            }
        }
Exemplo n.º 5
0
        static void DeserializeOneLizard(string filename)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            using (TextReader reader = new StreamReader(filename))
            {
                //read the file and store into a string
                string data = reader.ReadToEnd();

                //data cast to LIZARD, deserialize and store on the Lizard list.
                Lizard lizard = serializer.Deserialize <Lizard>(data);

                Console.WriteLine(lizard);
            }
        }