C#将json转化为对象
本帖最后由 ZZtiWater 于 2013-11-12 15:13:06 编辑
public class TempContacts
{
public string DisplayName { get; set; }
public string Email { get; set; }
}
string jsonContacts="[{"DisplayName":"name1","Email":"email1"},{"DisplayName":"name2","Email":"email2"}]";
Models.TempContacts contacts = JsonConvert.DeserializeObject<Models.TempContacts>(jsonContacts);
class Program
{
static void Main(string[] args)
{
string jsonContacts = "[{"DisplayName":"name1","Email":"email1"},{"DisplayName":"name2","Email":"email2"}]";
List<TempContacts> list = JsonConvert.DeserializeObject<List<TempContacts>>(jsonContacts);
}
}
public class Data
{
public List<TempContacts> list { get; set; }
}
public class TempContacts
{
public string DisplayName { get; set; }
public string Email { get; set; }
}
string jsonContacts="[{"DisplayName":"name1","Email":"email1"},{"DisplayName":"name2","Email":"email2"}]";
IList<Models.TempContacts> contactsList = JsonConvert.DeserializeObject<Models.TempContacts>(jsonContacts);