我的输入如下:
[{"somenums":"1","someDate":"2014年1月1日","viewdata":"1119958","visitdata":"152452","uniquedata":"125873"},{"somenums":"2","someDate":"2.1.2014","viewdata":"1863752","visitdata":"241453","uniquedata":"200762"}]
我还没能找到很多关于如何处理这样一个包含多行的文件的信息。我发现的一点信息是Json将把方括号中的对象反序列化为List。
在摸索着消除语法错误后,我得到了下面的代码,但在语句jrrows = DirectCast(JsonConvert.
等上得到了运行时InvalidDirectCast异常。
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Settings.LastJsonFileDirectory = Path.GetDirectoryName(ofd.FileName)
My.Settings.Save()
Dim sr As New StreamReader(ofd.FileName)
Dim jrrows As List(Of JsonRow)
jrrows = DirectCast(JsonConvert.DeserializeObject(sr.ReadToEnd), List(Of JsonRow))
End If
End Sub
End Class
<Serializable()> _
Public Class JsonRow
Public somenums As String
Public someDate As String
Public viewdata As String
Public visitdata As String
Public uniquedata As String
Sub New() 'we need a parameter-less constructor to make it serializable
End Sub
End Class
在C#中。。。
string json=File.ReadAllText(ofd.FileName);
List<JsonRow> mydata = JsonConvert.Deserialize<List<JsonRow>>(json);
在VB.NET(自动翻译)中
Dim json As String = File.ReadAllText(ofd.FileName)
Dim mydata As List(Of JsonRow) = JsonConvert.Deserialize(Of List(Of JsonRow))(json)