deep serialization?

Jun 9, 2009 at 10:30 PM

I was wondering if json.NET handles deep serialization? I saw another post - Embedded Objects, that some basically asked

the same thing and a followup poster indicated json.NET handles this situation. I have json response to deserialize on my client

app in this format:

 Status : string,
BytesRead : int,
BytesTotal : int,
PercentComplete : int,
BytesPerSec : int,
Message : string,
SecsRemaining : int,
SecsElapsed : int,
CurrentFileName : string,
ProcessingState : string,
Files : [ ControlUniqueID: int, FileName: string, ContentType: string ContentLength: string ]

In my .NET app, I define the following classes to represent this data:

 public class UploadFiles
{
    public string ControlUniqueID { get; set; }
    public string FileName { get; set; }
    public string ContentType { get; set; }
    public int ContentLength { get; set; }
}

[JsonObject(MemberSerialization.OptIn)]
public class UploadProgress
{
    [JsonProperty]
    public string Status { get; set; }
    [JsonProperty]
    public int BytesRead { get; set; }
    [JsonProperty]
    public int BytesTotal { get; set; }
    [JsonProperty]
    public int PercentComplete { get; set; }
    [JsonProperty]
    public int SecsRemaining { get; set; }
    [JsonProperty]
    public string ProcessingState { get; set; }

    // the remaining properties will not be parsed
    public int BytesPerSec { get; set; }
    public string Message { get; set; }
    public int SecsElapsed { get; set; }
    public string CurrentFileName { get; set; }

    [JsonProperty]
    public UploadFiles Files;
}

I make the following call to deserialize my response:

string jsonResponse = GetJsonProgress();
UploadProgress deserializedProgress = JsonConvert.DeserializeObject<UploadProgress>(jsonResponse);

and get the error:

"Cannot create and populate list type Uploader.Form1+UploadFiles."

Can json.NET handle more than a single level of serialization? Is there something special I have to do to get the Files

object to be successfully processed?

 

Thanks for your help

Coordinator
Jun 9, 2009 at 10:59 PM

Try changing "public UploadFiles Files;" to "public List<UploadFiles> Files;"