我无法反序列化这个 JSON。
JSON 看起来像这样:
{
"ticker": {
"high": 91.489,
"low": 88.3,
"avg": 89.8945,
"vol": 233637.9876,
"vol_cur": 2588.09448,
"last": 90.48,
"buy": 90.55,
"sell": 90.48,
"updated": 1372613806,
"server_time": 1372613807
}
}
我的功能是这样的:
Private Function Btce(ByVal Address As String) As String
Dim rt As String = ""
Dim out As String
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
Dim Time As Date
Time = Now()
wRequest = WebRequest.Create(Address)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim testObj = js.Deserialize(rt, New Object().GetType())
Dim high = testObj("High")
Dim low = testObj("Low")
Dim avg = testObj("Average")
Dim vol = testObj("Volume")
Dim last = testObj("Last")
Dim buy = testObj("Buy")
Dim sell = testObj("Sell")
out = "Data from btc-e.com" + Environment.NewLine
out += (Time) + Environment.NewLine
out += "High: " + Environment.NewLine
out += "Low: " + Environment.NewLine
out += "Average: " + Environment.NewLine
out += "Volume: " + Environment.NewLine
out += "Last: " + Environment.NewLine
out += "Buy: " + Environment.NewLine
out += "Sell: "
Return out
End Function
然后我在控制台中得到这个:
Microsoft.VisualBasic.dll 中出现“System.Collections.Generic.KeyNotFoundException”类型的未处理异常附加信息:字典中不存在给定键。