ToObject() - LinkedList

Aug 27, 2012 at 3:45 PM
Edited Aug 27, 2012 at 3:46 PM

I've a problem to convert a json string to a LinkedList<myclass> object.

From LinkedList to json instead works.

The method 

public object ToObject(string json, Type type)
go to 
(o as List<object>).ToArray();
and return null.
Can you help me ?
Thanks !!!!
Aug 27, 2012 at 5:35 PM

Post your code you are using.

Aug 29, 2012 at 7:47 AM
Edited Sep 5, 2012 at 3:36 PM

This is the class to serializer

  public class foto

        public string filename { get; set; }
        public string title { get; set; }
        //public string people { get; set; }
        public string events { get; set; }
        public string place { get; set; }
        public string type { get; set; }
        public string comment { get; set; }
        public int yeardate { get; set; }
        public string monthdate { get; set; }
        public double stars { get; set; }
        public string privates { get; set; }
        public string lat { get; set; }
        public string lon { get; set; }

This is the object:
public static LinkedList<JsonCreator.foto> Album = new LinkedList<foto>();

 And the code:
  using (StreamReader sr = new StreamReader(file))
                    string fileData = sr.ReadToEnd();
                    //Album = fastJSON.JSON.Instance.ToObject<LinkedList<JsonCreator.foto>>(fileData);
                    Album = (LinkedList<JsonCreator.foto>)fastJSON.JSON.Instance.ToObject(fileData, typeof(LinkedList<JsonCreator.foto>));

I think that I have to use the serialize and deserialize method but I have not found any examples.
Sep 5, 2012 at 3:34 PM


Sep 5, 2012 at 4:03 PM

I had a look (I have never used the linked list), it seems that it's a hard class to work with, the serializer works like a list, but the class lacks a generic Add method (AddAfter,AddBefore) which makes it difficult for the deserializer.