Katazui Katazui -4 years ago 478
JSON Question

Cannot implicitly convert type 'Newtonsoft.Json.Linq.JToken' to 'string'. An explicit conversion exists (are you missing a cast?)

I have the following code:

WebClient c = new WebClient();
var data = c.DownloadString("https://btc-e.com/api/2/btc_usd/ticker");
JObject o = JObject.Parse(data);
maskedTextBox11.Text = o["high"];

But it's giving the error in the title.

Answer Source

You are just required to add o["high"].ToString(); instead of o["high"]; since JObject[] returns a JToken and you are trying to assign maskedTextBox11.Text, which is a string, with it.

If you want the ToString() of the object represented by the token you can do it as the following:

MyType obj = o["high"].ToObject<MyType>();
string s = obj.ToString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download