[JSON] Keine Ausgabe nach dem deserialisieren

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von KaskadekingDE.

    [JSON] Keine Ausgabe nach dem deserialisieren

    Hallo,

    ich stehe derzeit vor ein Problem dass JSON mit bei "name" nichts ausgibt. Ich hab schon ziemlich viele Möglichkeiten probiert. Entweder gibt er mir nichts aus oder er wirft eine Exception das der Wert nicht null sein darf. Deserialisieren tue ich mit JSON .NET und hab echt keine Ahnung woran das liegt ?(

    Der JSON String sieht so aus:


    Spoiler anzeigen

    Quellcode

    1. {
    2. "libraries": [
    3. {
    4. "name": "java3d:vecmath:1.3.1"
    5. },
    6. {
    7. "name": "net.sf.trove4j:trove4j:3.0.3"
    8. },
    9. {
    10. "name": "com.ibm.icu:icu4j-core-mojang:51.2"
    11. },
    12. {
    13. "name": "net.sf.jopt-simple:jopt-simple:4.5"
    14. },
    15. {
    16. "name": "com.paulscode:codecjorbis:20101023"
    17. },
    18. {
    19. "name": "com.paulscode:codecwav:20101023"
    20. },
    21. {
    22. "name": "com.paulscode:libraryjavasound:20101123"
    23. },
    24. {
    25. "name": "com.paulscode:librarylwjglopenal:20100824"
    26. },
    27. {
    28. "name": "com.paulscode:soundsystem:20120107"
    29. },
    30. {
    31. "name": "io.netty:netty-all:4.0.10.Final"
    32. },
    33. {
    34. "name": "com.google.guava:guava:15.0"
    35. },
    36. {
    37. "name": "org.apache.commons:commons-lang3:3.1"
    38. },
    39. {
    40. "name": "commons-io:commons-io:2.4"
    41. },
    42. {
    43. "name": "commons-codec:commons-codec:1.9"
    44. },
    45. {
    46. "name": "net.java.jinput:jinput:2.0.5"
    47. },
    48. {
    49. "name": "net.java.jutils:jutils:1.0.0"
    50. },
    51. {
    52. "name": "com.google.code.gson:gson:2.2.4"
    53. },
    54. {
    55. "name": "com.mojang:authlib:1.5.13"
    56. },
    57. {
    58. "name": "org.apache.logging.log4j:log4j-api:2.0-beta9"
    59. },
    60. {
    61. "name": "org.apache.logging.log4j:log4j-core:2.0-beta9"
    62. },
    63. {
    64. "name": "org.lwjgl.lwjgl:lwjgl:2.9.1"
    65. },
    66. {
    67. "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.1"
    68. },
    69. {
    70. "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.1",
    71. "natives": {
    72. "linux": "natives-linux",
    73. "windows": "natives-windows",
    74. "osx": "natives-osx"
    75. },
    76. "extract": {
    77. "exclude": [
    78. "META-INF/"
    79. ]
    80. }
    81. },
    82. {
    83. "name": "net.java.jinput:jinput-platform:2.0.5",
    84. "natives": {
    85. "linux": "natives-linux",
    86. "windows": "natives-windows",
    87. "osx": "natives-osx"
    88. },
    89. "extract": {
    90. "exclude": [
    91. "META-INF/"
    92. ]
    93. }
    94. },
    95. {
    96. "name": "tv.twitch:twitch:5.16"
    97. },
    98. {
    99. "name": "tv.twitch:twitch-platform:5.16",
    100. "rules": [
    101. {
    102. "action": "allow"
    103. },
    104. {
    105. "action": "disallow",
    106. "os": {
    107. "name": "linux"
    108. }
    109. }
    110. ],
    111. "natives": {
    112. "linux": "natives-linux",
    113. "windows": "natives-windows-${arch}",
    114. "osx": "natives-osx"
    115. },
    116. "extract": {
    117. "exclude": [
    118. "META-INF/"
    119. ]
    120. }
    121. },
    122. {
    123. "name": "tv.twitch:twitch-external-platform:4.5",
    124. "rules": [
    125. {
    126. "action": "allow",
    127. "os": {
    128. "name": "windows"
    129. }
    130. }
    131. ],
    132. "natives": {
    133. "windows": "natives-windows-${arch}"
    134. },
    135. "extract": {
    136. "exclude": [
    137. "META-INF/"
    138. ]
    139. }
    140. }
    141. ]
    142. }


    Verwendeter Code:

    VB.NET-Quellcode

    1. Dim names = JsonConvert.DeserializeObject(Of libraries)(VersionConfigLibrarie)
    2. MessageBox.Show(names.name)

    KaskadekingDE on GitHub :)
    Bitte keine Fragen über Programmierung per PN! Dafür ist das Forum hier.

    Who cares? ¯\_(ツ)_/¯

    VB.NET-Quellcode

    1. Public Class Natives
    2. Public Property linux() As String
    3. Get
    4. Return m_linux
    5. End Get
    6. Set
    7. m_linux = Value
    8. End Set
    9. End Property
    10. Private m_linux As String
    11. Public Property windows() As String
    12. Get
    13. Return m_windows
    14. End Get
    15. Set
    16. m_windows = Value
    17. End Set
    18. End Property
    19. Private m_windows As String
    20. Public Property osx() As String
    21. Get
    22. Return m_osx
    23. End Get
    24. Set
    25. m_osx = Value
    26. End Set
    27. End Property
    28. Private m_osx As String
    29. End Class
    30. Public Class Extract
    31. Public Property exclude() As List(Of String)
    32. Get
    33. Return m_exclude
    34. End Get
    35. Set
    36. m_exclude = Value
    37. End Set
    38. End Property
    39. Private m_exclude As List(Of String)
    40. End Class
    41. Public Class Os
    42. Public Property name() As String
    43. Get
    44. Return m_name
    45. End Get
    46. Set
    47. m_name = Value
    48. End Set
    49. End Property
    50. Private m_name As String
    51. End Class
    52. Public Class Rule
    53. Public Property action() As String
    54. Get
    55. Return m_action
    56. End Get
    57. Set
    58. m_action = Value
    59. End Set
    60. End Property
    61. Private m_action As String
    62. Public Property os() As Os
    63. Get
    64. Return m_os
    65. End Get
    66. Set
    67. m_os = Value
    68. End Set
    69. End Property
    70. Private m_os As Os
    71. End Class
    72. Public Class Library
    73. Public Property name() As String
    74. Get
    75. Return m_name
    76. End Get
    77. Set
    78. m_name = Value
    79. End Set
    80. End Property
    81. Private m_name As String
    82. Public Property natives() As Natives
    83. Get
    84. Return m_natives
    85. End Get
    86. Set
    87. m_natives = Value
    88. End Set
    89. End Property
    90. Private m_natives As Natives
    91. Public Property extract() As Extract
    92. Get
    93. Return m_extract
    94. End Get
    95. Set
    96. m_extract = Value
    97. End Set
    98. End Property
    99. Private m_extract As Extract
    100. Public Property rules() As List(Of Rule)
    101. Get
    102. Return m_rules
    103. End Get
    104. Set
    105. m_rules = Value
    106. End Set
    107. End Property
    108. Private m_rules As List(Of Rule)
    109. End Class
    110. Public Class RootObject
    111. Public Property libraries() As List(Of Library)
    112. Get
    113. Return m_libraries
    114. End Get
    115. Set
    116. m_libraries = Value
    117. End Set
    118. End Property
    119. Private m_libraries As List(Of Library)
    120. End Class
    121. ...
    122. Dim names = JsonConvert.DeserializeObject(Of RootObject)(VersionConfigLibrarie)
    Ah ok.

    EDIT: Wie kann ich dann z.B Name auslesen? Auf "name" kann ich von RootObject nicht zugreifen und wenn ich mir ein Item von "libraries" auslesen will komm nur "Test.Library" was aber nicht hinhaut.
    KaskadekingDE on GitHub :)
    Bitte keine Fragen über Programmierung per PN! Dafür ist das Forum hier.

    Who cares? ¯\_(ツ)_/¯

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „KaskadekingDE“ ()

    Das Problem ist ich kann nicht darauf zugreifen.
    Es steht dann einfach da:
    "name" ist kein Member von "System.Collections.Generic.List(Of Test.libraries)". C:\Users\KaskadekingDE\documents\visual studio 2013\Projects\Test\Test\test.vb 96 30 Test
    KaskadekingDE on GitHub :)
    Bitte keine Fragen über Programmierung per PN! Dafür ist das Forum hier.

    Who cares? ¯\_(ツ)_/¯