Vb.NET Deserialise JSON List in Object

I could not find the exact answer for which I think that I will have a crack asking a question.

I am currently trying to deserialize a JSON string into an object in vb.NET using Json.NET; I did a bit earlier by tweaking the appropriate classes and then deserializing the string to an object using the parent class, and they worked fine, but this one seems to be not quite right.

An example of the line I'm trying to break is as follows:

   [
    {
        "value": 12345,
        "text": "Example Unique Text"
    },
    {
        "InnerList": [
            {
                "value": 4746,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4747,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4748,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4749,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4750,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4751,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4752,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4753,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4754,
                "text": "A duplicated entry of text"
            },
            {
                "value": 4755,
                "text": "A duplicated entry of text"
            }
        ],
        "duplicated": "Yes"
    },
    {
        "value": 15298,
        "text": "Another Example Unique Text"
    },
    {
        "value": 959,
        "text": "Yet more uniqueness"
    },
    {
        "value": 801,
        "text": "A final little bit of unique text"
    }
]

I tried passing this through a series of external tools, and they all return with the same class definitions, but they don't seem to work. Therefore, based on my understanding of JSON, I compiled the following:

 Public Class ItemDetails

        Public Value As Integer
        Public Text As String

 End Class

 Public Class ItemArray

        Public DetailList As List(Of ItemDetails)
        Public Duplicated As String

 End Class

 Public Class GeneralArray

        Public GeneralList As List(Of ItemArray)

 End Class

GeneralArray is the parent class and is used to parse JSON.

. JSON, JSONStringCollection - , GeneralArray:

Dim JSONString As String

JSONString = "<JSONStringDetails>"

Dim JSONObj = JsonConvert.DeserializeObject(Of JSONStringCollection.GeneralArray)(JSONString)

, , :

"Newtonsoft.Json.JsonSerializationException" Newtonsoft.Json.dll

: JSON (, [1,2,3]) "ShadOS.JSONStringCollection + GeneralArray", type JSON (, { "name": "value" }) .

?

+4
1

JSON ( , [ ]).

: " ". GeneralArray (, / ).

, JSON "" - , ItemDetails , ItemArray. , VB.NET, .

ItemDetails ItemArray

Public Class CombinedItem
    'properties from ItemDetails
    Public Value As Integer
    Public Text As String

    'properties from ItemArray
    Public InnerList As List(Of CombinedItem)
    Public Duplicated As String

End Class

, :

Dim JSONObj = JsonConvert.DeserializeObject(Of List(Of CombinedItem))(JSONString)

, Newtonsoft, - List(Of CombinedItem) - /, .

JSONObj CombinedItem - Value/Text, InnerList/Duplicated.

+3

All Articles