This project is read-only.

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

Jan 24, 2013 at 11: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.



           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\");

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

            var readFromZipFile = string.Empty;

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

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