VB.net JSON DeserializeObject错误BC30203

时间:2016-09-07 14:40:36

标签: json vb.net serialization

我使用Newtonsoft.dll创建了一个Settings.json文件。我有一个表示设置的类,我在加载应用程序时保存和反序列化时序列化。除了一件事,一切都很好,很快。

settings类包含一个名为SpeechSynthesizer的.NET对象。在反序列化设置后,我会在BC30203: Identifier expected的{​​{1}}子对象上获得Voice。这导致反序列化返回默认的`Voice' (Anna)设置而不是保存的设置(序列化设置对象确实可以正常工作)正确反序列化此子对象之前对象的设置。

JSON:

SpeechSynthesizer

反序列化代码:

{ ...... "Speech": { "State": 0, "Rate": -3, "Volume": 67, "Voice": { "Gender": 1, "Age": 30, "Name": "IVONA 2 Ruben", "Culture": "nl-NL", "Id": "IVONA 2 Voice Ruben22", "Description": "IVONA 2 Ruben - Dutch male voice [22kHz]", "SupportedAudioFormats": [], "AdditionalInfo": { "Language": "413", "Name": "IVONA 2 Ruben", "Age": "Adult", "Gender": "Male", "Vendor": "IVONA Software Sp. z o. o." } } }

序列化代码:

Return JsonConvert.DeserializeObject(Of Settings)(File.ReadAllText(settingsfile))

设置代码:

    Using _file As StreamWriter = New StreamWriter(SettingFilePath)
        Dim serializer As New JsonSerializer()
        serializer.Formatting = Formatting.Indented
        serializer.Serialize(_file, Me)
    End Using

Image of the error

1 个答案:

答案 0 :(得分:0)

我的问题的答案是,正如Mark所指出的那样,对象是ReadOnly意味着它在应用程序启动期间无法Deserialize Deserializing

工作是通过添加一个名为SelectedVoice的额外设置作为字符串。启动时,我使用SpeechSynthesizer.SelectVoice(_Settings.SelectedVoice)加载用户设置的语音。