Unexpected character encountered while parsing value: . Path '', line 0, position 0

Jan 24, 2013 at 10:58 AM

 

Hallo I get this error when I save a txt file in an archive and then I try to access it again. The txt file contains a serialized object that I serialize by using Json.Net.

Here is the code:

The Dog class is a very simple class containing only two properties:

    public class Dog
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

 

Then the code I use in order to serialize, archive and then access the file is this:

On the last line I will get the error.

  

Thanks

           var list = new List<Dog>();          
            list.Add(new Dog { FirstName = "Arasd", LastName = "1234123" });
            list.Add(new Dog { FirstName = "fghfgh", LastName = "vbnvbn" });

            var serialized = JsonConvert.SerializeObject(list, Formatting.Indented);


            var zipFile = new ZipFile(@"C:\Users\daviko\Desktop\test.zip");

            using (zipFile)
            {
                zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                zipFile.UpdateEntry("dogs.txt", serialized, UTF8Encoding.UTF8);
                zipFile.Save();
            }

            var readFromZipFile = string.Empty;

            using (var input = new MemoryStream())
            {
                using (zipFile)
                {
                    var entry = zipFile["dogs.txt"];
                    entry.Extract(input);
                }
                using (var output = new MemoryStream())
                {
                    input.CopyTo(output);
                    readFromZipFile = new UTF8Encoding().GetString( input.ToArray());
                }
            }

            var deserialized = JsonConvert.DeserializeObject<List<Dog>>(readFromZipFile);