简体   繁体   English

VB.net JSON DeserializeObject错误BC30203

[英]VB.net JSON DeserializeObject error BC30203

I'm using the Newtonsoft.dll to create a Settings.json file. 我正在使用Newtonsoft.dll创建一个Settings.json文件。 I have a class that represents the settings, which i serialize upon saving and deserialize when loading the application. 我有一个代表设置的类,在加载应用程序时会在保存时进行序列化并反序列化。 Everything is working great and fast except for one thing. 除了一件事,一切都运转良好而快速。

The settings class contains an .NET object called SpeechSynthesizer . 设置类包含一个名为SpeechSynthesizer的.NET对象。 When the settings is deserialized i get an BC30203: Identifier expected at the Voice child object of the SpeechSynthesizer . 将设置反序列化后,我得到一个BC30203: Identifier expectedBC30203: Identifier expectedVoice子对象处BC30203: Identifier expectedSpeechSynthesizer This causes the deserialized returning the default `Voice' (Anna) settings instead of the saved one's (Serializing the setting object does work as it should) The settings of the object before this child object are properly deserialized. 这会导致反序列化返回默认的“语音”(Anna)设置,而不是已保存的设置(对设置对象进行序列化确实可以正常工作)。对该子对象之前的对象的设置进行了正确的反序列化。

The JSON: JSON:

  {      ......
  "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."
      }
    }
  }

Deserialize Code: 反序列化代码:

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

Serialize Code: 序列化代码:

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

Settings Code: 设置代码:

''' <summary>
''' Get or Set the properties that is used for the SpeechSynthesizer
''' </summary>
''' <returns></returns>
Public Property Speech As SpeechSynthesizer

Image of the error 错误图片

The answer to my question was, as Mark pointed out, the object was ReadOnly Meaning it couldn't Deserialize during application startup Deserializing 正如Mark所指出的,我的问题的答案是该对象为ReadOnly这意味着在应用程序启动期间无法对它进行Deserialize Deserializing

The work arround is by adding a extra setting i called SelectedVoice As a string. 工作环境是通过添加一个称为“ SelectedVoice作为字符串”的额外设置。 Upon startup i use the SpeechSynthesizer.SelectVoice(_Settings.SelectedVoice) To load the voice that was set by the user. 启动时,我使用SpeechSynthesizer.SelectVoice(_Settings.SelectedVoice)加载用户设置的语音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM