反序列化的正确方法是什么?

时间:2015-03-19 02:48:07

标签: json vb.net linq

你好我使用json_encode在.txt文件中保存一个php数组,接下来我需要在vb.net中使用这个数组,但实际上我可以做一段时间或每个, 这是数组字符串

"[{"Id_Event":"5713616","Deporte":"Soccer","Pais":"Austria Amateur","Liga":"Regionalliga East","Jornada":"20","Local":"SKU Amstetten","Visita":"Wiener SC Axa","Fecha_Evento":"2015-03-18T19:30:00","encuentros":[{"Items":[{"Por":"1","Fila":"3way15713616","Cuota":"1.9","$$hashKey":"019"}],"Tipo":"3way","Gan_Max":1.9,"$$hashKey":"017"}],"$$hashKey":"015"},{"Id_Event":"6804834","Deporte":"Soccer","Pais":"England Amateur","Liga":"Southern Football League,","Jornada":"1","Local":"Cambridge City","Visita":"Frome Town","Fecha_Evento":"2015-03-18T20:45:00","encuentros":[{"Items":[{"Por":"1","Fila":"3way16804834","Cuota":"1.7","$$hashKey":"01F"}],"Tipo":"3way","Gan_Max":1.7,"$$hashKey":"01D"}],"$$hashKey":"01B"}]"

在项目中我有Imports Newtonsoft.Json.Linq

请帮帮我

1 个答案:

答案 0 :(得分:1)

您可以将json反序列化为List(Of JObject),以便能够迭代json数组的最简单方法:

Dim jsonString As String = "your_json_text"
Dim json As List(Of JObject) = JsonConvert.DeserializeObject(Of List(Of JObject))(jsonString)
For Each jObject As JObject In json
    Console.WriteLine(jObject)
Next

更好的方法是创建一个类来映射json数组中的每个项目,然后将json反序列化为List(Of YourClass)而不是List(Of JObject)