-3

I need to load JSON from a URL, and not know why (in this format).

In this ask, all solved: Dynamically load Json from URL on C#

But at this time, i need parse this JSON:

{"Markets":[{"Label":"CHEESE/BTC","Name":"Cheese","Price":0.00000012,"Volume_24h":0.26702542,"Timestamp":1524662820}]}

The format of JSON is diferent. Tryed like this, but not work:

json = webClient.DownloadString("https://www.worldcoinindex.com/apiservice/ticker?key=0b6dmpsEyLlR7meh1QfALwEGE6dC3J&label=cheesebtc&fiat=btc");

dynamic obj = JsonConvert.DeserializeObject(json);

 if (obj.success == "true")
 {
     foreach (var result in obj.result)
     {
         if (result.Name == "Price")
             textbox1.text = result.value.ToString();
     }
 }
DhavalR
  • 1,409
  • 3
  • 29
  • 57

1 Answers1

2

Make a model as below. And explicitly convert dynamic obj to that class.

public class Markets
{
    public string Label { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public decimal Volume_24h { get; set; }
    public string Timestamp { get; set; }
}


dynamic obj = JsonConvert.DeserializeObject<Markets>(json);

Or

Markets obj = JsonConvert.DeserializeObject<Markets>(json);
DhavalR
  • 1,409
  • 3
  • 29
  • 57