我有一个类,如下代码。 我试图将其转换为XML和JSON,但它们都返回空值:{}
Public Class PivotSet
Public Shared Property selectedlines As Boolean()
Public Shared Property selectedlabels As Boolean()
Public Shared Property linescolors As Integer()
Public Shared Property labelcolors As Integer()
Public Shared Property linethick As Boolean()
Public Shared Property labelbold As Boolean()
Public Shared Property pivotPeriod As String
Public Sub New()
selectedlines = {True, True, True, True, True, True, True}
selectedlabels = {True, True, True, True, True, True, True}
linescolors = {16711680, 255, 255, 255, 32768, 32768, 32768}
labelcolors = {16711680, 255, 255, 255, 32768, 32768, 32768}
linethick = {True, True, True, True, True, True, True}
labelbold = {True, True, True, True, True, True, True}
pivotPeriod = "Yearly"
End Sub
以及以下代码将其转换为 XML:
Dim settings As New PivotSet
Dim x As New Xml.Serialization.XmlSerializer(settings.GetType)
Dim js As New JsonSerializer()
Dim fs As New FileStream("d:set.xml", FileMode.Create)
Dim writer As New StreamWriter(fs, New System.Text.UTF8Encoding)
'serialize to XML
x.Serialize(writer, settings)
'serialize to json
File.WriteAllText("d:Settings.json", JsonConvert.SerializeObject(settings))
但是 JSON 的结果是 {},XML 的结果也是
<?xml version="1.0" encoding="utf-8"?>
<PivotSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
有人可以帮助我解决问题吗?
从属性中删除共享,它应该可以工作:
Public Property selectedlines As Boolean()
Public Property selectedlabels As Boolean()
Public Property linescolors As Integer()
Public Property labelcolors As Integer()
Public Property linethick As Boolean()
Public Property labelbold As Boolean()
Public Property pivotPeriod As String