我在这样的网络服务器中有一个 JSON:
{"My Book List": [{"ID":"5","TYPE":"History","TITLE":"Ekannoborti","PRICE":"200","IMAGE":"Ekannoborti.jpg","DOWNLOAD LINK":"http://www.starhostbd.com/"}],"success":3}
为了反序列化它,我到目前为止已经完成了:
public class Attributes
{
public string ID{ get; set; }
public string TYPE { get; set; }
public string TITLE { get; set; }
public string PRICE { get; set; }
public string IMAGE { get; set; }
public string DOWNLOADLINK { get; set; }
}
public class DataJsonAttributeContainer
{
public List<Attributes> attributes { get; set; }
//public Attributes attributes { get; set; }
}
public static T DeserializeFromJson<T>(string json)
{
T deserializedProduct = JsonConvert.DeserializeObject<T>(json);
return deserializedProduct;
}
& 在我的代码中:
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//var deserializedJSON = JsonConvert.DeserializeObject<Attributes>(e.Result);
var container = DeserializeFromJson<DataJsonAttributeContainer>(e.Result);
string asd = container.attributes[0].DOWNLOADLINK[0].ToString();
//string asd = deserializedJSON.DOWNLOADLINK[0].ToString();
}
问题是:从调试窗口中,我可以看到在 e.Result 中分配了数据,但容器仍然为空。如何解决这个问题呢 ?请帮忙 !