示例#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");
        }
示例#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);
     }
 }
示例#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);
            }
        }
示例#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);
            }
        }
示例#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);
            }
        }