自引用循环错误

时间:2017-05-28 17:30:24

标签: json vb.net self-reference

我有一个自引用循环。我尝试阅读并实现其他一些答案,但似乎没有用。我有一个类将对象保存为json文件(方法)。它尝试序列化对象,但会引发自引用循环的异常。我序列化的对象是第二个块(类)。我该如何解决这个问题?它确实有用,直到我添加了按钮,所以我假设我在处理程序上做错了,但我真的不知道。

  Public Sub saveLocalSettings()
        Console.WriteLine("saveLocalSettings")
        If Not Directory.Exists(_SettingsFile) Then
            Directory.CreateDirectory(_SettingsFile)
        End If
        '  Try
        Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, PreserveReferencesHandling.Objects)
        'Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, Newtonsoft.Json.ReferenceLoopHandling.Ignore)
        lm.writeFile(_SettingsFile + _FileName, strConfigurationManager, True)
        '  Catch ex As Exception
        ' End Try
    End Sub

Imports Newtonsoft.Json
Public Class RGOSetting
    Public Property id As String
    Public Property title As String
    Private mtbTitle As New MaskedTextBox
    Public Property sharestatus As Integer
    Public Property settingstring As String
    Public Property userid As Integer
    Public Property setting_profiles As New List(Of RGOSettingProfile)
    Private rgolcm As RGOLeagueChampionManager
    '  Private rgolssm As RGOLeagueSumSpManager
    Public btnUpdate As New Button
    Public btnReset As New Button
    Public btnClear As New Button
    End Class

Public Class RGOSettingProfile
    Public Property champion As LeagueChampion
    Public Property summoner_spells As New List(Of LeagueSummonerSpell)

    Public Sub New()
    End Sub

Public Sub New(ByVal strChampion As String, ByVal strSummonerSpell As List(Of String))
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我最后用按钮做了这个,它允许我保存对象:

_get_my_tid()