我需要決議來自加密交換 API 的 JSON。在這種情況下,我需要決議我的未結訂單。如果沒有未結訂單,則 Json 為:
{"error":null,"result":{"KIBAUSDT":{"limit":100,"offset":0,"total":0,"records":null}},"id":299639536}
這似乎是一本字典。一旦我創建了 1 個訂單,Json 就會變成這樣:
{"error":null,"result":{"KIBAUSDT":{"limit":100,"offset":0,"total":1,"records":[{"user":2996434,"id":82651361103,"market":"KIBAUSDT","freeze":"0.001","fee_stock":"","source":"web","type":1,"side":2,"ctime":1645022087.403207,"mtime":1645022087.403207,"price":"0.00001","amount":"100","taker_fee":"0.0035","maker_fee":"-0.003","left":"100","deal_stock":"0","deal_money":"0","deal_fee":"0","alt_fee":"0","deal_fee_alt":"0","status":0}]}},"id":305636871}
這似乎更像一個陣列(如果我錯了,請糾正我)。這些行是為我正在創建的每個訂單創建的。因此,在
it is kind of weird how I'm getting the first error "FromJson is not a member of kibausdt", since total property is inside the Kibausdt class. This issue is solved by using Dim total = Example.FromJson((Await s)) but I'm not really sure that's the answer.
Thanks
uj5u.com熱心網友回復:
Public Async Function ExecuteAsync() As Task
Dim wc As New WebClient
'you can await this task and get the json string result instead of adding it to a list first
Dim json = Await wc.DownloadStringTaskAsync("https://api.hotbit.io/api/v1/order.pending?market=KIBA/USDT&offset=0&limit=100&api_key=44812d8f-66d3-01c0-94c3b29305040b03&sign=F3330B924E1873B9C8FAB40A25D7B851")
'deserialize the json
Dim rootObject = Example.FromJson(json)
'navigate to Kibausdt
Dim kibausdt = rootObject.result.KIBAUSDT
'check total
If kibausdt.total = 0 Then
RichTextBox1.Text = "0 opened orders"
Else
'loop through records
For Each record In kibausdt.records
Dim side As String = record.side.ToString()
Dim amount As Long = record.amount
Dim price As String = record.price
RichTextBox1.Text &= side & amount & price
Next
End If
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426188.html
