Json formatında veri çekme
private void button1_Click(object sender, EventArgs e)
{
string adres = "https://koineks.com/ticker";
WebRequest istek = HttpWebRequest.Create(adres);
WebResponse cevap;
cevap = istek.GetResponse();
StreamReader donenBilgiler = new StreamReader(cevap.GetResponseStream());
string bilgilerial = donenBilgiler.ReadToEnd();
List<Para.BCH> parabilgisi = JsonConvert.DeserializeObject<List<Para.BCH>>(bilgilerial);
foreach (var bilgi in parabilgisi)
{
ListViewItem okunan = new ListViewItem(
new string[]{
bilgi.name,bilgi.current.ToString()});
listView1.Items.Add(okunan);
}
}
public class Para
{
public class BTC
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class ETH
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class LTC
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class DOGE
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class DASH
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class XRP
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class XLM
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class XEM
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class BCH
{
public string short_code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public string current { get; set; }
public string change_amount { get; set; }
public int change_percentage { get; set; }
public string high { get; set; }
public string low { get; set; }
public string volume { get; set; }
public string ask { get; set; }
public string bid { get; set; }
public int timestamp { get; set; }
}
public class RootObject
{
public BTC BTC { get; set; }
public ETH ETH { get; set; }
public LTC LTC { get; set; }
public DOGE DOGE { get; set; }
public DASH DASH { get; set; }
public XRP XRP { get; set; }
public XLM XLM { get; set; }
public XEM XEM { get; set; }
public BCH BCH { get; set; }
}
}
}
aldığım hata :
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[denemee.Para+BCH]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'BTC', line 1, position 7.