Lord, does not come out with JSON like:

{ "success": true, "message": "", "result": [ { "MarketName": "BTC-DCR", "High": 0.00276762, "Low": 0.00261059, "Volume": 2011.69194218, "Last": 0.002637, "BaseVolume": 5.33707839, "TimeStamp": "2016-08-08T22:02:25.687", "Bid": 0.002637, "Ask": 0.00270211, "OpenBuyOrders": 148, "OpenSellOrders": 809, "PrevDay": 0.00269298, "Created": "2016-02-09T21:06:51.577" } ] } 

Yuzayu Newtonsoft JSON. I'm trying like this:

 JObject o = JObject.Parse(jsondcrbtc); dcr_to_btc = Convert.ToString(o["result"]["Last"]); 

What am I doing wrong?

3 answers 3

 public class Result { public string MarketName { get; set; } public double High { get; set; } public double Low { get; set; } public double Volume { get; set; } public double Last { get; set; } public double BaseVolume { get; set; } public string TimeStamp { get; set; } public double Bid { get; set; } public double Ask { get; set; } public int OpenBuyOrders { get; set; } public int OpenSellOrders { get; set; } public double PrevDay { get; set; } public string Created { get; set; } } public class RootObject { public bool success { get; set; } public string message { get; set; } public List<Result> result { get; set; } } public static class Class1 { public static string js = "{" + "\"success\": true," + "\"message\": \"\"," + "\"result\": [" + " {" + "\"MarketName\": \"BTC-DCR\"," + "\"High\": 0.00276762," + "\"Last\": 0.002637," + "\"Created\": \"2016-02-09T21:06:51.577\"" + "}" + "]" + "}"; public static void run() { JObject o = JObject.Parse(js); RootObject obj = new RootObject(); obj.result = JsonConvert.DeserializeObject<List<Result>>(o.Root["result"].ToString()); foreach (var ro in obj.result) { Console.WriteLine($"Last: {ro.Last}"); Console.WriteLine($"High: {ro.High}"); } } } 

The code of the Result and RootObject classes Result automatically generated here on the model of the JSON presented.

  • Thanks, it works :) - Professor Fortran

In your JSON, "result" is an array, so before taking the value "Last" , you need to decide which element of the array you are accessing.

    I understand that it is outdated, but completely working piece.) Simple and primitive:

     async public void GetData(string pair) { string queryStr = string.Format("https://btc-e.nz/api/2/{0}/ticker", pair); var client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(new Uri(queryStr)); var jsonString = await response.Content.ReadAsStringAsync(); var resultat = JObject.Parse(jsonString)["ticker"]; data = (string)resultat["last"]; }