This project has moved and is read-only. For the latest updates, please go here.

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; }

public class UploadProgress
    public string Status { get; set; }
    public int BytesRead { get; set; }
    public int BytesTotal { get; set; }
    public int PercentComplete { get; set; }
    public int SecsRemaining { get; set; }
    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; }

    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

Jun 9, 2009 at 10:59 PM

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