ToObject() - LinkedList

Aug 27, 2012 at 4:45 PM
Edited Aug 27, 2012 at 4: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 !!!!
Coordinator
Aug 27, 2012 at 6:35 PM

Post your code you are using.

Aug 29, 2012 at 8:47 AM
Edited Sep 5, 2012 at 4:36 PM

This is the class to serializer

  public class foto

    {
        [DataMember]
        public string filename { get; set; }
 
        [DataMember]
        public string title { get; set; }
 
        //[DataMember]
        //public string people { get; set; }
 
        [DataMember]
        public string events { get; set; }
 
        [DataMember]
        public string place { get; set; }
 
        [DataMember]
        public string type { get; set; }
 
        [DataMember]
        public string comment { get; set; }
 
        [DataMember]
        public int yeardate { get; set; }
 
        [DataMember]
        public string monthdate { get; set; }
 
        [DataMember]
        public double stars { get; set; }
 
        [DataMember]
        public string privates { get; set; }
 
        [DataMember]
        public string lat { get; set; }
 
        [DataMember]
        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();
                    sr.Close();
                    //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.
Thanks
Sep 5, 2012 at 4:34 PM

UP

Coordinator
Sep 5, 2012 at 5: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.