I have a JSON in a web server like this :
{"My Book List": [{"ID":"5","TYPE":"History","TITLE":"Ekannoborti","PRICE":"200","IMAGE":"Ekannoborti.jpg","DOWNLOAD LINK":"http://www.starhostbd.com/"}],"success":3}
To deserialize it I have done so far :
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;
}
& in my code :
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();
}
The problem is : From debug wiindow i can see that data is assigned in e.Result but container remains null . How to solve this problem ? Please help !
string asd = container.attributes[0].DOWNLOADLINK.ToString();to obtain the whole link. In your case you obtain only the first character.