下面解析JSON的代码不起作用。我究竟做错了什么?需要帮助解析JSON
string jsonText =
@"{
""John Doe"":{
""email"":""[email protected]"",
""ph_no"":""4081231234"",
""address"":{
""house_no"":""10"",
""street"":""Macgregor Drive"",
""zip"":""12345""
}
},
""Jane Doe"":{
""email"":""[email protected]"",
""ph_no"":""4081231111"",
""address"":{
""house_no"":""56"",
""street"":""Scott Street"",
""zip"":""12355""
}
}
}"
public class Address {
public string house_no { get; set; }
public string street { get; set; }
public string zip { get; set; }
}
public class Contact {
public string email { get; set; }
public string ph_no { get; set; }
public Address address { get; set; }
}
public class ContactList
{
public List<Contact> Contacts { get; set; }
}
class Program
{
static void Main(string[] args)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
ContactList cl = serializer.Deserialize<ContactList>(jsonText);
}
}
感谢
什么是你的错误? – 2011-03-10 21:10:05
你有什么样的问题,是不是编译,返回null,抛出异常? – 2011-03-10 21:10:17
任何错误消息/例外?目前还不确定,但不要认为您使用了对象名称的双引号,例如“”John Doe“”成为John Doe。 – StuperUser 2011-03-10 21:10:25