H
HansvB69
Guest
Hi,
Ik have a json object and i want to deserialize it. After some searching i made this but there is something wrong with it. Result is empty.
private void Button2_Click(object sender, EventArgs e)
{
//the json object:
//{\"1\":{\"symbol\":\"BTC\",\"cap\":190543515710.2,\"change\":{\"hour\":-0.230294,\"day\":-0.524608},\"price\":10719.7326423,\"coinheat\":100,\"url\":\"https:\\/\\/chasing-coins.com\\/coin\\/BTC\"}
//fetch the data
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://chasing-coins.com/api/v1/top-coins/20");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
richTextBox1.Text = sr.ReadToEnd(); //Just to see the string
sr.Close();
//deserialize json object
string json = richTextBox1.Text;
var result = JsonConvert.DeserializeObject<RootObject>(json); //--> there is no result. (result = null)
var capi = result.Coin.Select(p => p.BTC).ToList(); //p.cap , p.change --> all empty
}
}
public class Coin
{
public string symbol { get; set; }
public string BTC { get; set; }
public string cap { get; set; }
public string change { get; set; }
public string hour { get; set; }
public string day { get; set; }
public string price { get; set; }
public string coinheat { get; set; }
public string url { get; set; }
public string https { get; set; }
}
public class RootObject
{
public List<Coin> Coin { get; set; }
}
Continue reading...
Ik have a json object and i want to deserialize it. After some searching i made this but there is something wrong with it. Result is empty.
private void Button2_Click(object sender, EventArgs e)
{
//the json object:
//{\"1\":{\"symbol\":\"BTC\",\"cap\":190543515710.2,\"change\":{\"hour\":-0.230294,\"day\":-0.524608},\"price\":10719.7326423,\"coinheat\":100,\"url\":\"https:\\/\\/chasing-coins.com\\/coin\\/BTC\"}
//fetch the data
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://chasing-coins.com/api/v1/top-coins/20");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
richTextBox1.Text = sr.ReadToEnd(); //Just to see the string
sr.Close();
//deserialize json object
string json = richTextBox1.Text;
var result = JsonConvert.DeserializeObject<RootObject>(json); //--> there is no result. (result = null)
var capi = result.Coin.Select(p => p.BTC).ToList(); //p.cap , p.change --> all empty
}
}
public class Coin
{
public string symbol { get; set; }
public string BTC { get; set; }
public string cap { get; set; }
public string change { get; set; }
public string hour { get; set; }
public string day { get; set; }
public string price { get; set; }
public string coinheat { get; set; }
public string url { get; set; }
public string https { get; set; }
}
public class RootObject
{
public List<Coin> Coin { get; set; }
}
Continue reading...