我有一个JSON返回,看起来像这样:JSON数组的VB.NET JSON阵列 - 反序列化
{"coin1":{"available":"0.00000000","onOrders":"0.00000000","btcValue":"0.00000000"},
"coin2":{"available":"0.00000000","onOrders":"0.00000000","btcValue":"0.00000000"},
"coin3":{"available":"0.00000000","onOrders":"0.00000000","btcValue":"0.00000000"}
}
我想它返回到“coinName”的列表。
我做:
Public Class coinName
Public Vals As cValues
End Class
Public Class cValues
Public available As String
Public onOrders As String
Public btcValue As String
End Class
,我使用下面的代码进行反序列化:
Dim pData = JsonConvert.DeserializeObject(Of List(Of coinName))(bals)
“BALS” 是一个字符串形式的JSON回报。
我收到以下错误:
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[WindowsApplication21.coinName]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '1CR', line 1, position 7.
任何帮助将不胜感激。
谢谢。
我认为你的JSON结构不正确。 JSON数组应该如下:''汽车':[“福特”,“宝马”,“菲亚特”]'你不应该使用** {} ** – Mederic
因此,回到结构,我认为你仍然缺少** [] **基本上你应该有:''coin3“:[{”available“:”0.00000000“,”onOrders“:”0.00000000“,”btcValue“:”0.00000000“}]'尝试运行你的代码更正的JSON看它是否工作。 – Mederic
{“coin1”:[{“available”:“0.00000000”,“onOrders”:“0.00000000”,“btcValue”:“0.00000000”}],“coin2”:[{“available”:“0.00000000”,“onOrders “:”0.00000000“,”btcValue“:”0.00000000“}],”coin3“:[{”available“:”0.00000000“,”onOrders“:”0.00000000“,”btcValue“:”0.00000000“}]} 不起作用 –