0

This is the json string I need to deserialize:

[{"id":5236083584722820,"name":"IT_Projects","accessLevel":"EDITOR"},
{"id":2034305724639108,"name":"IT_Task","accessLevel":"EDITOR"},
{"id":2249810003683204,"name":"On-Hold","accessLevel":"EDITOR"}]

Here is the code:

[DataContract]
public class SSCollection
{    
    [DataMember]
    public List<SSheets> sheetObjects { get; set; }
} 
[DataContract]
public class SSheets 
{
    [DataMember]
    public Int64 id { get; set; }
    [DataMember]
    public string name { get; set; }
    [DataMember]
    public string accessLevel { get; set;}
}

using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
        {
            memoryStream.Position = 0;
            var serializer = new DataContractJsonSerializer(typeof(SSCollection));
            SSCollection ss = (SSCollection)serializer.ReadObject(memoryStream);                 
            return ss;
        }

I'm not sure how to handle the json string, it appears to be an array but is not named. I've tried with using the SSheets DataContract and with using SSCollection, both return nulls except when I use SSheets i get a 0 for id and nulls for the strings name and accessLevel. Any help will be greatly appreciated. thanks.

1 Answers1

0

AFter reading many other questions on this subject and reading their sugggestions to use Json.Net I have decided to use Newtonsoft.Json. It worked on the first try. .Net DataContract just not worth the hassle. Thanks for your help.