Skip to content

Instantly share code, notes, and snippets.

@jackinf
Created February 26, 2014 08:47
Show Gist options
  • Save jackinf/9225965 to your computer and use it in GitHub Desktop.
Save jackinf/9225965 to your computer and use it in GitHub Desktop.
JSON Serialization and Deserialization in C#
private class AdditionalInfoJson
{
public bool hasErrors { get; set; }
public List<string> errors { get; set; }
}
...
// data = Json(new { hasErrors = true, errors }, JsonRequestBehavior.AllowGet)
string json = new JavaScriptSerializer().Serialize(data.Data);
var tempRecord = JsonConvert.DeserializeObject<AdditionalInfoJson>(json);
Assert.IsTrue(tempRecord.hasErrors);
Assert.AreEqual(7, tempRecord.errors.Count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment