我曾尝试查看与我类似的类似Stack Overflow问题,但这些解决方案似乎都无法解决我的问题。所以我再问一次。
我将项目属性更改为.NET Framework 4,在进行了一些在线研究后,人们一直说这是一个更好的框架。最初,我一直在使用.NET Framework 4.6.1。
我尝试了MSDN网页并整合了命名空间和程序集,但我只会遇到更多错误。
我的错误是:
错误BC30002类型' JavaScriptSerializer'不是 定义。 VB_to_JSON_One C:\ Users \ cmannar \ source \ repos \ VB_to_JSON_One \ VB_to_JSON_One \ Module1.vb 8 Active
我的警告是:
警告BC40056导入中指定的命名空间或类型 ' System.Web.Script.Serialization'不包含任何公共成员或 无法找到。确保定义名称空间或类型 包含至少一个公共成员。确保导入的元素 名字不使用任何名称 别名。 VB_to_JSON_One C:\ Users \ cmannar \ source \ repos \ VB_to_JSON_One \ VB_to_JSON_One \ Module1.vb 2 Active
我正在使用Visual Studios 2017,我正在尝试将.NET转换为JSON,如下面的代码所示:
Imports System.Web.Script.Serialization ' Sytem.web.extensions.dll
Imports System.IO
Imports System.Text
Module Module1
Public serializer As New JavaScriptSerializer()
Sub Main()
Dim fileData() As String = File.ReadAllText("JSON_Data.txt").Split(vbLf)
Dim datapoints As New List(Of DataPoint)
For Each jsonData As String In fileData
If jsonData.Trim() <> "" Then datapoints.AddRange(getDeserialisedChargeHRData(jsonData))
Next
Dim sortedDataPoints As List(Of DataPoint) = datapoints.OrderBy(Function(o) o.dateTime).ToList()
Dim sb As New StringBuilder()
sb.AppendLine("Date and time,BPM,Confidence,Calories burned,Default zone,Custom zone")
For Each dp As DataPoint In datapoints
sb.AppendLine(String.Format("{0},{1},{2},{3},""{4}"",""{5}""", dp.dateTime, dp.bpm, dp.confidence, dp.caloriesBurned, dp.defaultZone, dp.customZone))
Next
File.WriteAllText("BMP_Data.csv", sb.ToString())
End Sub
Public Function getDeserialisedChargeHRData(ByVal json As String) As List(Of DataPoint)
Dim deserializedResult = serializer.Deserialize(Of List(Of RootObject))(json)
Return deserializedResult.Item(0).dataSets.activity.dataPoints
End Function
End Module
Public Class DataPoint
Public Property bpm() As Integer
Public Property confidence() As Integer
Public Property caloriesBurned() As Double
Public Property defaultZone() As String
Public Property customZone() As String
Public Property dateTime() As Date
End Class
Public Class Activity
Public Property dataPoints() As List(Of DataPoint)
Public Property granularity() As String
End Class
Public Class DataSets
Public Property activity() As Activity
End Class
Public Class RootObject
Public Property dataSets() As DataSets
End Class
如果有人有任何建议或想法,我们将不胜感激!