我正在使用VB.NET中的產品,並使用NewtonSoft的JSON類來處理JSON。我不知道如何使用它,但我似乎無法確定文檔。基本上,給定一個JSON字符串,我想提取金額值。下面是我有:如何使用NewtonSoft的JSON類反序列化JSON對象?
Dim serverResponse as String
Dim urlToFetch as String
Dim jsonObject as Newton.JSON.JSONConvert
Dim wc as new System.Net.WebClient
Dim amountHeld as String
urlToFetch = "someurl"
serverResponse = wc.DownloadString(urlToFetch)
jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject(serverResponse)
現在,在這一點上,我希望能夠做一個
amountHeld = jsonObject.Name["amount"]
獲得量的價值,但我不能。我顯然是做錯了。什麼是正確的方法來做到這一點?
謝謝! 安東尼
什麼是'serverResponse'的價值?只需在'amountHeld'行代碼處添加一個斷點並檢查'jsonObject'的值。 – Styxxy
serverResponse保存服務器返回的JSON字符串。我已經驗證了這一點。我遇到的問題是我知道如何將其分配給jsonObject,但不知道如何檢索特定的鍵。 – CajunTechie