下面解析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