If I have a class Contact:
public class Contact
{
public Contact()
{
}
public int ID { get; set;}
public string firstName { get; set;}
public string lastName { get; set;}
}
in my code I instantiate 5 different Contact objects and their specific properties and then put them into a List<Contact>.
My questions:
- How can I convert the
List<Contact>to JSON? - How can I read the JSON back to a
List<Contact>? - How can I read from JSON the contact with ID 123 and instantiate a
Contactobject out of it so I have all the properties?
Much appreciated your help!
Thanks!
P.S. The JSON will look something like this ?:
{
contacts:{
contact:[
{
id:123,
firstname:'jhon',
lastname:'smith'
},
{
id:1234,
firstname:'robert',
lastname:'smith'
}
]
}
}
A quick search of the web reveals suggestions for the JavaScriptSerializer
I suggest you give it a try.
Source here