Skip to content

Instantly share code, notes, and snippets.

@jamesantrobus
Created February 14, 2011 18:58
Show Gist options
  • Save jamesantrobus/826348 to your computer and use it in GitHub Desktop.
Save jamesantrobus/826348 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace jittest
{
public class Test
{
public void SerializeDeserialiseTest()
{
Person person = new Person("james");
person.Pets.Add(new Pet("Rex", "Dog"));
string json = JsonConvert.SerializeObject(person);
//throws System.TypeInitializationException when ran on a device (Attempted JIT compile)
Person deserialized = JsonConvert.DeserializeObject<Person>(json);
}
}
public class Person
{
[MonoTouch.Foundation.Preserve]
public Person() {}
public Person(string name)
{
Name = name;
Pets = new List<Pet>();
}
public string Name;
public List<Pet> Pets;
}
public class Pet
{
public Pet(string name, string type)
{
Name = name;
Type = type;
}
public string Name {get;set;}
public string Type {get;set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment