我正在尝试获取Json值并将其放在标签中,语法似乎是正确的,但确定代码有问题,该值根本不会显示在Label上。它能是什么?
注意:我已经添加了Newstonsoft JSON引用,计时器为5秒,并在加载表单后激活。
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim json = New IO.StreamReader(DirectCast(DirectCast(Net.WebRequest.Create("https://www.bitstamp.net/api/ticker/"), Net.HttpWebRequest).GetResponse, Net.HttpWebResponse).GetResponseStream)
Dim rq As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(json.ReadToEnd)
BitCoinPrice = $"{rq.SelectToken("last")}"
Label1.Text = BitCoinPrice
End Sub
答案 0 :(得分:0)
我很疏忽,但意识到我把代码放在错误的位置激活 Timer1 ,而不是在表单加载时放置它,它是在 WebBrowser1 时负荷。
<强>错误强>
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Enabled = True 'Wrong Place
End Sub
<强>正确强>
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True 'Correct Place
End Sub
很抱歉给您带来不便,感谢您的帮助。