I have jquery looping through a html table and putting it into an object then using JSON.stringify to convert that javascript object to json , see json below
{
"0":{"name":"fdgd","surname":"ssdt"},
"1":{"name":"fdsf","surname":"vn"},
"2":{"name":"dfsb","surname":"mry"},
"3":{"name":"hsdsdfry","surname":"smh"}
}
My issue is with JSON.net and the CLASSs im am trying to match up for it to convert the json into my tableT object
After it does the Jsonconvert I get empty objects, can you please tell me what is wrong with my classs. Im using vb.net and .net 2. So I guess my question is how do I match my tableT class up to my json string? Thank you for the help.
Dim tableOBJ As tableT = JsonConvert.DeserializeObject(Of tableT)(myJSON)
Public Class tableT
Private _allRows As List(Of Rows)
Property AllRows As List(Of Rows)
Get
Return _allRows
End Get
Set(ByVal value As List(Of Rows))
_allRows = value
End Set
End Property
End Class
Public Class Rows
Private _name As String
Private _surname As String
Property name As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Property surname As String
Get
Return _surname
End Get
Set(ByVal value As String)
_surname = value
End Set
End Property
End Class
Without testing it, it appears that
should really be something more like
since there isn’t any way for JsonConvert to know that you want the rows in the AllRows object.
So, your code would look more like:
** EDIT **
After testing this, I was only able to get this to work by modifying the Json string to look more like what I understand a Json array should look like.
Specifically, if I changed the array to look like:
Then your original code works correctly.
What your original Json is doing is expecting that there are properties in the class called 0, 1, 2, and 3 of type Rows, which is not possible with VB and is, I am certain, not what you are looking to accomplish.
You can verify this by adding properties for Zero, One, Two, and Three of type Rows to your tableT:
changing your json to:
and deserializing using your original class. You will see then that the new properties are populated with the contents of your json string.