1

The following URL represents a long string of data: http://api.bitcoincharts.com/v1/markets.json

I noticed at the end of the url it was a .json extension, so I already researched about that.

Ive downloaded JSON.NET and referenced it in my c#.net source.

Within this long string, I need to get the following data off the "symbol": "mtgoxUSD" and place it on my form;

1) "bid" 2) "high" 3) "ask" 4) "avg" 5) "low"

I am really confused on how to properly extract this data as the URL is one huge string.

The following snippet below is what I have coded so far as I am stumped on how to continue.

public void Grab()
    {
        using (var tradeClient = new System.Net.WebClient())
        {
            var json = tradeClient.DownloadString("http://api.bitcoincharts.com/v1/markets.json");
        }
    }

Please guide me or reference me on how to get started as I have never dealt with a json extension or file before!

Thanks!

Andrew
  • 552
  • 2
  • 10
  • 29

2 Answers2

0

You could use JArray array = (JArray) JsonConvert.DeserializeObject(json); using the Newtonsoft.Json.Linq library

aquaraga
  • 4,138
  • 23
  • 29
0

try this:

using (WebClient wc = new WebClient())
{
    var json = wc.DownloadString("http://coderwall.com/mdeiters.json");
    var arrJson = JsonConvert.DeserializeObject<string[][]>(json);
}

Or you can create an Object/Class and Convert this json into that Object. See this link for your reference. See sample code and class below:

using (WebClient wc = new WebClient())
{
    var json = wc.DownloadString("http://coderwall.com/mdeiters.json");
    var jsonMarket = JsonConvert.DeserializeObject<Market>(json);
}

public class Market
{
    [JsonProperty("high")]
    public string High{ get; set; }

    [JsonProperty("latest_trade")]
    public string LatestTrade { get; set; }

    [JsonProperty("bid")]
    public string Bid{ get; set; }

    [JsonProperty("volume")]
    public string Volume{ get; set; }

    [JsonProperty("currency")]
    public string Currency{ get; set; }

    [JsonProperty("currency_volume")]
    public string CurrencyVolume{ get; set; }

    [JsonProperty("ask")]
    public string Ask { get; set; }

    [JsonProperty("close")]
    public string Close { get; set; }

    [JsonProperty("avg")]
    public string AVG { get; set; }

    [JsonProperty("symbol")]
    public string Symbol { get; set; }

    [JsonProperty("low")]
    public string Low { get; set; }
}
Community
  • 1
  • 1
roybalderama
  • 1,650
  • 21
  • 38