Trouble parsing Json into .net Object - json

I've studied other questions like this and I'm not doing something right. My vb.net class is wrong or something. Should my class only try to represent from candidates on or what?
I need help with deserializing this json:
{
"spatialReference" : {
"wkid" : 2286
},
"candidates" : [
{
"address" : "100 MAIN ST",
"location" : {
"x" : 1144782.9490543604,
"y" : 81361.525678694248
},
"score" : 100,
"attributes" : {
}
},
{
"address" : "100 E MAIN ST",
"location" : {
"x" : 1120908.3257195801,
"y" : 169917.71846333146
},
"score" : 77,
"attributes" : {
}
}
]
}
I am using the following code to deserialize:
Public Shared Function Deserialise(Of T)(ByVal json As String) As T
Dim obj As T = Activator.CreateInstance(Of T)()
Using ms As MemoryStream = New MemoryStream(Encoding.Unicode.GetBytes(json))
Dim serializer As DataContractJsonSerializer = New DataContractJsonSerializer(obj.GetType())
obj = serializer.ReadObject(ms)
Return obj
End Using
End Function
And my vb.net class looks like this:
<DataContract()> _
Public Class SearchResults
Private mCandidates() As candidate
<DataContract()> _
Public Class SpatialReference
Private mwkId As String
<DataMember()> _
Public Property wkid() As String
Get
Return mwkId
End Get
Set(ByVal value As String)
mwkId = value
End Set
End Property
End Class
<DataMember()> _
Public Property Candidates() As candidate()
Get
Return mCandidates
End Get
Set(ByVal value As candidate())
mCandidates = value
End Set
End Property
End Class
<DataContract()> _
Public Class candidate
Private mAddress As String
Private mLocation As Location
Private mScore As String
Private mAttr As String
<DataMember()> _
Public Property address() As String
Get
Return mAddress
End Get
Set(ByVal value As String)
mAddress = value
End Set
End Property
<DataMember()> _
Public Property location() As Location
Get
Return mLocation
End Get
Set(ByVal value As Location)
mLocation = value
End Set
End Property
<DataMember()> _
Public Property score() As String
Get
Return mScore
End Get
Set(ByVal value As String)
mScore = value
End Set
End Property
<DataMember()> _
Public Property attributes() As String
Get
Return mAttr
End Get
Set(ByVal value As String)
mAttr = value
End Set
End Property
End Class

I dont know .net but i can tell you it related to JAVA. You can relate this with .Net
When we need to serialize or deserialize our class objects to json or from json we need Gson,
In Java we generally import tha package Gson package create its object for example:-
Suppose i have a class User, whose object you wanna serialize. Now to do this
take the whole object covert it to JSON with some key name with the help of Gson
jsonObject.put("KEYFORTHISjsonObject", gson.toJson(userClassObject));
Now you have serialized it to JSON,
While deserializing it
just create ur User object. Get Json Object from Json file
JSONObject jsonObject = new JSONObject(jsonFile.toString())
userObject2 = gson.fromJson(jsonObject.toString(), User.class);
so now userObject2 has all the values that you serialized earlier.
if you are not familiar with JAVA then Read about Gson for .net
or you can read this link as well http://james.newtonking.com/projects/json-net.aspx

Related

How to deserialize nested JSON arrays with Json.Net?

I want to deserialize the response of a HTTP-Request to Objects.
The Response looks like this:
[
"BeginOfEnumerable",
[
{
"StatusID": 12345,
"ItemID": 987654
}
],
"EndOfEnumerable"
]
I am using Newtonsoft.Json.
I tried to use Visual Studio's Edit > Paste special > Paste JSON as Classes to create the class model, but the result looks strange to me:
Public Class Rootobject
Public Property Property1() As Object
End Class
Also, this throws an Exception:
Dim myObject As Rootobject = JsonConvert.DeserializeObject(response.Content)
ยป Unexpected character encountered while parsing value: .Path ", line
0, position 0.
I want to get the StatusID and ItemID.
A JSON Validator I used says this JSON is valid.
The JSON structure is valid, per se, you may have some difficulty with the strings that don't follow the name:value pattern.
You could deserialize only the inner array of values, as a List(class), e.g.,
Imports System.Collections.Generic
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Public Class EnumObject
Public Property StatusId As Long
Public Property ItemId As Long
End Class
'[...]
Dim jsonEnumsTokens = JArray.Parse(response.Content)
Dim enumsArray = jsonEnumsTokens.Children.Skip(1).First().ToObject(Of List(Of EnumObject))()
which returns the list of EnumObject that contain the values, if that's all you're interested in and you don't need to handle this JSON in any other way, or serialize it back in the same form.
If you want to get the JSON representation of the arrays only:
Dim justTheArraysJson = jsonEnumsTokens.Children.Skip(1).First().ToString()
In case you want to perform deserialization and serialization, maintaining the structure, you could use a custom JsonConverter that handles this case.
The EnumObjectsConverter creates an intermediate structure that contains both the single strings and the array of values, contained in the EnumObjectArray property.
This also allows to serialize back to the original structure, if needed.
Call it as:
Dim enumArray = EnumObjectsHandler.Deserialize(response.Content)
Dim serialized = EnumObjectsHandler.Serialize(enumArray)
The EnumObjectsHandler class that provides the static methods for the serialization:
Public Class EnumObjectsHandler
Private Shared settings As JsonSerializerSettings = New JsonSerializerSettings() With {
.Converters = {New EnumObjectsConverter()}
}
Public Shared Function Deserialize(json As String) As List(Of EnumObjectsRoot)
Return JsonConvert.DeserializeObject(Of List(Of EnumObjectsRoot))(json, settings)
End Function
Public Shared Function Serialize(data As List(Of EnumObjectsRoot)) As String
Return JsonConvert.SerializeObject(data, settings)
End Function
Public Class EnumObject
Public Property StatusId As Long
Public Property ItemId As Long
End Class
Public Structure EnumObjectsRoot
Public Property EnumObjectArray As List(Of EnumObject)
Public Property Operation As String
Public Shared Widening Operator CType(objectArray As List(Of EnumObject)) As EnumObjectsRoot
Return New EnumObjectsRoot With {.EnumObjectArray = objectArray}
End Operator
Public Shared Widening Operator CType(op As String) As EnumObjectsRoot
Return New EnumObjectsRoot With {.Operation = op}
End Operator
End Structure
Friend Class EnumObjectsConverter
Inherits JsonConverter
Public Overrides Function CanConvert(t As Type) As Boolean
Return t Is GetType(EnumObjectsRoot)
End Function
Public Overrides Function ReadJson(reader As JsonReader, t As Type, existingValue As Object, serializer As JsonSerializer) As Object
Select Case reader.TokenType
Case JsonToken.String
Dim stringValue = serializer.Deserialize(Of String)(reader)
Return New EnumObjectsRoot() With {
.Operation = stringValue
}
Case JsonToken.StartArray
Dim arrayValue = serializer.Deserialize(Of List(Of EnumObject))(reader)
Return New EnumObjectsRoot() With {
.EnumObjectArray = arrayValue
}
End Select
Throw New Exception("EnumObjectsRoot could not be deserialized")
End Function
Public Overrides Sub WriteJson(writer As JsonWriter, untypedValue As Object, serializer As JsonSerializer)
Dim value = CType(untypedValue, EnumObjectsRoot)
If value.Operation IsNot Nothing Then
serializer.Serialize(writer, value.Operation)
Return
End If
If value.EnumObjectArray IsNot Nothing Then
serializer.Serialize(writer, value.EnumObjectArray)
Return
End If
Throw New Exception("EnumObjectsRoot could not be serialized")
End Sub
End Class
End Class

How to deserialize a List(Of Object) from JSON?

I have a List(Of Object) that I am using in a property of type IEnumerable(Of Object). I can serialize it fine but cannot work out then how to deserialize it from JSON back to a List(Of Object). Any help would be really great please.
My ViewModel:
Public Class ViewModel
Inherits ViewModelBase
Public Class MapSettings
<Display(Name:="Map Name", Description:="Enter a optional name for the map.", GroupName:="Map Settings")>
Public Property MapName As String
<Display(Name:="Map Description", Description:="Enter a optional description for the map.", GroupName:="Map Settings")>
Public Property MapDescription As String
<Display(Name:="Map Comments", Description:="Enter optional comments for the map.", GroupName:="Map Settings")>
Public Property MapComments As String
<Display(Name:="Map Version", Description:="Enter a optional version for the map.", GroupName:="Map Settings")>
Public Property MapVersion As String
End Class
Public Class GeneralSettings
<Display(Name:="Route Colour", Description:="Sets the colour of the routes design line on the map.", GroupName:="General Settings")>
Public Property Foreground As Color
End Class
Private _myItems() As IEnumerable(Of Object)
Public Property MyItems() As IEnumerable(Of Object)
Get
If _myItems Is Nothing Then
Return New List(Of Object)() From {
New MapSettings,
New GeneralSettings With {.Foreground = Colors.Blue}
}
Else
Return _myItems
End If
End Get
Set(value As IEnumerable(Of Object))
_myItems = value
OnPropertyChanged()
End Set
End Property
End Class
My serialize code that I cannot complete:
Dim MyItems_New = JsonConvert.DeserializeObject(Of MyItems???)(MyJsonString)
JSON:
{
"MyItems": [
{
"MapName": null,
"MapDescription": null,
"MapComments": null,
"MapVersion": null
},
{
"Foreground": "#FF0000FF"
}
]
}
I just found that Newtonsoft has built-in support for type handling, which can be enabled by setting the JsonSerializerSettings.TypeNameHandling property and passing it to the serialization methods. As long as you control the input, this should let you both serialize and deserialize your list without a problem.
Serialize:
Dim myItems = JsonConvert.SerializeObject(myVM.MyItems, Formatting.None, New JsonSerializerSettings() With { .TypeNameHandling = TypeNameHandling.Auto })
Deserialize:
Dim myItems_New = JsonConvert.DeserializeObject(Of List(Of Object))(MyJsonString, New JsonSerializerSettings() With { .TypeNameHandling = TypeNameHandling.Auto })
In your question, MyJsonString appears to be a serialized version of your ViewModel class rather than just the list itself. If this is the case, change DeserializeObject(Of List(Of Object)) to DeserializeObject(Of ViewModel).
Resulting JSON:
[
{
"$type": "MapSettings, YourProjectNamespace",
"MapName": "New York",
"MapDescription": "Map over New York",
"MapComments": null,
"MapVersion": "v1"
},
{
"$type": "GeneralSettings, YourProjectNamespace",
"Foreground": "#FF0000"
}
]
Try it online (C#):
https://dotnetfiddle.net/0jCIGL
However, if these two classes are all you are planning to use this list for, then you'd be better off using something along the lines of Jimi's proposed solution, as then you're always working with strongly-typed objects.

Newtonsoft JSON parsing into object

My VB is a bit rusty but I need to parse a JSON string. I did it already in C# where I didn't have an issue. This is an old project and I'm using VS2008 for it.
This is my class:
Public Class ResponseMeta
Private _type As String
<JsonProperty("type")> _
Public Property type() As String
Get
Return _type.ToString()
End Get
Set(ByVal value As String)
_type = value
End Set
End Property
Private _message As String
<JsonProperty("message")> _
Public Property message() As String
Get
Return _message
End Get
Set(ByVal value As String)
_message = value
End Set
End Property
Private _message_v1 As String
<JsonProperty("message-v1")> _
Public Property message_v1() As String
Get
Return _message_v1
End Get
Set(ByVal value As String)
_message_v1 = value
End Set
End Property
Private _message_v2 As String
<JsonProperty("message-v2")> _
Public Property message_v2() As String
Get
Return _message_v2
End Get
Set(ByVal value As String)
_message_v2 = value
End Set
End Property
Private _message_v3 As String
<JsonProperty("message-v3")> _
Public Property message_v3() As String
Get
Return _message_v3
End Get
Set(ByVal value As String)
_message_v3 = value
End Set
End Property
Private _message_v4 As String
<JsonProperty("message-v4")> _
Public Property message_v4() As String
Get
Return _message_v4
End Get
Set(ByVal value As String)
_message_v4 = value
End Set
End Property
End Class
The code to deserialize is:
Dim test As String
test = "{""response-meta"":{""type"":""S"",""message"":"""",""Total No Of Records"":"""",""message-v1"":""1"",""message-v2"":"""",""message-v3"":"""",""message-v4"":""""}}"
Dim testcl As ResponseMeta
testcl = JsonConvert.DeserializeObject(Of ResponseMeta)(test)
All properties of the object are set to Nothing and if I add watch, it says:
type = {"Object reference not set to an instance of an object."}
I have now spent countless hours on this and Google doesn't found a hint or a clue of what might be getting wrong here.
Any suggestions are very welcome.
The JSON does not match up to what you are trying to parse it to.
You are missing a root object.
Public Class RootObject
Private _root As ResponseMeta
<JsonProperty("response-meta")> _
Public Property ResponseMeta() As ResponseMeta
Get
Return _root
End Get
Set(ByVal value As ResponseMeta)
_root = value
End Set
End Property
End Class
So based on the JSON you would need to deserialize to root object first then get the meta data
Dim root As RootObject = JsonConvert.DeserializeObject(Of RootObject)(test)
Dim testcl As ResponseMeta = root.ResponseMeta

How to deserialize JSON which can be an array or a single object

I'm fairly new to using JSON.net and having trouble with some json I'm getting which sometime comes in as an array and sometimes as single object. Here is an example of what I'm seeing with the json
One way it comes in ...
{
"Make": "Dodge",
"Model": "Charger",
"Lines": [
{
"line": "base",
"engine": "v6",
"color": "red"
},
{
"line": "R/T",
"engine": "v8",
"color": "black"
}
],
"Year": "2013"
}
Another way it could come in
{
"Make": "Dodge",
"Model": "Charger",
"Lines": {
"line": "base",
"engine": "v6",
"color": "red"
},
"Year": "2013"
}
Here is what I've been using for code which works on the first way and throws an exception in the second case. Been scouring the web for ways to implement this and am really stuck.
Public Class jsonCar
Public Property make As String
Public Property model As String
Public Property lines As List(Of jsonCarLines)
Public Property year As String
End Class
Public Class jsonCarLines
Public Property line As String
Public Property engine As String
Public Property color As String
End Class
Module Module1
Private Const json As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": [{""line"":""base"",""engine"": ""v6"",""color"":""red""},{""line"":""R/T"",""engine"":""v8"",""color"":""black""}],""Year"":""2013""}"
'Private Const json As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": {""line"":""R/T"",""engine"":""v8"",""color"":""black""},""Year"":""2013""}"
Sub Main()
Dim car As jsonCar = JsonConvert.DeserializeObject(Of jsonCar)(json)
Console.WriteLine("Make: " & car.make)
Console.WriteLine("Model: " & car.model)
Console.WriteLine("Year: " & car.year)
Console.WriteLine("Lines: ")
For Each ln As jsonCarLines In car.lines
Console.WriteLine(" Name: " & ln.line)
Console.WriteLine(" Engine: " & ln.engine)
Console.WriteLine(" Color: " & ln.color)
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
I'm guessing this will likely need a custom JsonConverter, but I'm a bit at a loss as to how to set that up.
Here is how to get the SingleOrArrayConverter solution in the linked duplicate question working for your use case.
First, here is the VB-translated converter code. Take this and save it to a class file somewhere in your project. You can then easily reuse it for any future cases like this.
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Public Class SingleOrArrayConverter(Of T)
Inherits JsonConverter
Public Overrides Function CanConvert(objectType As Type) As Boolean
Return objectType = GetType(List(Of T))
End Function
Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
Dim token As JToken = JToken.Load(reader)
If (token.Type = JTokenType.Array) Then
Return token.ToObject(Of List(Of T))()
End If
Return New List(Of T) From {token.ToObject(Of T)()}
End Function
Public Overrides ReadOnly Property CanWrite As Boolean
Get
Return False
End Get
End Property
Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
Throw New NotImplementedException
End Sub
End Class
Now that you have this converter, any time you have a property that can be either a list or a single item, all you have to do is declare it as a list in your class and then annotate that list with a JsonConverter attribute such that it uses the SingleOrArrayConverter class. In your case, that would look like this:
Public Class jsonCar
Public Property make As String
Public Property model As String
<JsonConverter(GetType(SingleOrArrayConverter(Of jsonCarLines)))>
Public Property lines As List(Of jsonCarLines)
Public Property year As String
End Class
Then, just deserialize as you normally would, and it works as expected.
Dim car As jsonCar = JsonConvert.DeserializeObject(Of jsonCar)(json)
Here is a complete demonstration: https://dotnetfiddle.net/msYNeQ
You could achieve this to modify your jsonCar class like below
Public Class jsonCar
Public Property make As String
Public Property model As String
Public Property linesCollection As List(Of jsonCarLines) // Change name
Public Property lines As String // Change the type to string
Public Property year As String
End Class
And the code should be like below:
Dim car As jsonCar = JsonConvert.DeserializeObject(Of jsonCar)(json)
If (car.lines.StartsWith("[")) Then
car.linesCollection = JsonConvert.DeserializeObject(List(Of jsonCarLines))(car.lines)
Else
car.linesCollection = new List(Of jsonCarLines)
car.linesCollection.Add(JsonConvert.DeserializeObject(Of jsonCarLines)(car.lines))
EndIf
Thanks to both crowcoder & Kundan. I combined the two approaches and came up with something that works with both json inputs. Here is the final code.
Public Class jsonCar
Public Property make As String
Public Property model As String
Public Property linesArray As List(Of jsonCarLines)
Public Property year As String
End Class
Public Class jsonCarLines
Public Property line As String
Public Property engine As String
Public Property color As String
End Class
Module Module1
'Private Const json As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": [{""line"":""base"",""engine"": ""v6"",""color"":""red""},{""line"":""R/T"",""engine"":""v8"",""color"":""black""}],""Year"":""2013""}"
Private Const json As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": {""line"":""R/T"",""engine"":""v8"",""color"":""black""},""Year"":""2013""}"
Sub Main()
Dim obj As JObject = JsonConvert.DeserializeObject(json)
Dim ln As JToken = obj("Lines")
Dim car As jsonCar = JsonConvert.DeserializeObject(Of jsonCar)(json)
If (ln.GetType() Is GetType(Newtonsoft.Json.Linq.JArray)) Then
car.linesArray = JsonConvert.DeserializeObject(Of List(Of jsonCarLines))(JsonConvert.SerializeObject(ln))
End If
If (ln.GetType() Is GetType(Newtonsoft.Json.Linq.JObject)) Then
car.linesArray = New List(Of jsonCarLines)
car.linesArray.Add(JsonConvert.DeserializeObject(Of jsonCarLines)(JsonConvert.SerializeObject(ln)))
End If
Console.WriteLine("Make: " & car.make)
Console.WriteLine("Model: " & car.model)
Console.WriteLine("Year: " & car.year)
Console.WriteLine("Lines: ")
For Each line As jsonCarLines In car.linesArray
Console.WriteLine(" Name: " & line.line)
Console.WriteLine(" Engine: " & line.engine)
Console.WriteLine(" Color: " & line.color)
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Big thanks for the quick replies. This solved something I'd been spending a lot time off-and-on trying to figure out.
You can generically deserialize to Object and then inspect what you have. You can check for a JArray or JObject and act accordingly. You don't even need to deserialize into a specific type, you can work with the Dynamic objects but that may not be the best idea.
Module Module1
Sub Main()
Dim jsonWithArray As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": [{""line"":""base"",""engine"": ""v6"",""color"":""red""},{""line"":""R/T"",""engine"":""v8"",""color"":""black""}],""Year"":""2013""}"
Dim jsonWithObject As String = "{""Make"":""Dodge"",""Model"":""Charger"",""Lines"": {""line"":""base"",""engine"": ""v6"",""color"":""red""},""Year"":""2013""}"
Dim witharray As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonWithArray)
Dim withstring As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonWithObject)
Dim jtokArray As Newtonsoft.Json.Linq.JToken = witharray("Lines")
Dim jtokStr As Newtonsoft.Json.Linq.JToken = withstring("Lines")
If (jtokArray.GetType() Is GetType(Newtonsoft.Json.Linq.JArray)) Then
Console.WriteLine("its an array")
End If
If (jtokStr.GetType() Is GetType(Newtonsoft.Json.Linq.JObject)) Then
Console.WriteLine("its an object")
End If
Console.ReadKey()
End Sub
End Module

Working with nested json file visual basic

i have a nested json file that i want to deserialize, i keep getting an error " Object reference not set to an instance of an object."
here is my json file
[
{
"Name": "Junius",
"LastName": "Lekgwara",
"CellNo": [
{
"CellC": "072685345",
"Voda": "0728589303"
}
]
},
{
"Name": "Phuti",
"LastName": "Gravel",
"CellNo": [
{
"CellC": "08377777777",
"Voda": "089888888888"
}
]
},
{
"Name": "Donald",
"LastName": "Gravel",
"CellNo": [
{
"CellC": "0791408989",
"Voda": "0117689009"
}
]
}
]
here is my Person class
Public Class Person
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Public Property cellno As CellNo
End Class
Public Class CellNo
Public Property CellC As String
Public Property Voda As String
End Class
PersonList class
Public Class PersonList
Private _ListPerson As List(Of Person)
Public Property ListPerson() As List(Of Person)
Get
Return _ListPerson
End Get
Set(ByVal value As List(Of Person))
_ListPerson = value
End Set
End Property
Sub New()
_ListPerson = New List(Of Person)
End Sub
End Class
reading json file, when this sub is called i get an error
Public Async Sub LoadFromFile()
Dim reader As String = Await GetFile()
Dim serializer As DataContractJsonSerializer = New DataContractJsonSerializer(GetType(ObservableCollection(Of Person)))
Dim ms As MemoryStream = New MemoryStream(Encoding.UTF8.GetBytes(reader))
Dim listOf As ObservableCollection(Of Person) = New ObservableCollection(Of Person)
listOf = serializer.ReadObject(ms)
For Each item In listOf
list.ListPerson.Add(item)
Debug.WriteLine(item.Name + " " + item.LastName + " " + item.cellno.CellC + " " + item.cellno.Voda) 'Object reference not set to an instance of an object, on item.cellno.CellC and item.cellno.Voda
Next
End Sub
i want to be able to reference it like
Dim person As Person = New Person()
lblName.Text = person.Name
lblLastName.Text = person.LastName
lblCellCNo.Text= person.cellno.CellC
lblCellVodaNo.Text= person.cellno.Voda
how can i fix this?
The JSON shown is a bit different than the class structs you want to use. Person is a List or Array already in the JSON. CellNo is also an array even though it appears in that sample to only have one class object per person.
So, you can skip your PersonList entirely:
Public Class CellNo
Public Property CellC As String
Public Property Voda As String
End Class
Public Class Person
Public Property Name As String
Public Property LastName As String
Public Property CellNo As List(Of CellNo)
End Class
Deserialize to a List(Of Person):
Dim jstr = ... (wherever it comes from)
Dim jp As List(Of Person)
jp = JsonConvert.DeserializeObject(Of List(Of Person))(jstr)
This is now quite usable as is without further manipulations:
For Each P As Person In jp
Console.WriteLine("{0} Cell Voda:{1}", P.Name, P.CellNo(0).Voda)
Next
Junius Cell Voda: 0728589303
Phuti Cell Voda: 089888888888
Donald Cell Voda: 0117689009
Optionally, you can deserialize to an array of Person, and define Person.CellNo as an array also.
i'm not using newtonsoft
You get the same results using NET:
Imports System.Web.Script.Serialization
Dim jss As New JavaScriptSerializer
Dim jp As List(Of Person)
jp = jss.Deserialize(Of List(Of Person))(jstr)
See.. your problem is that
the item List is not well prepared for what you want.
item.cellno HAS CHILD !!!
and
item.cellno.CellC
item.cellno.Voda
must be iterated..
For Each item In listOf
list.ListPerson.Add(item)
'Debug.WriteLine(item.Name + " " + item.LastName + " " + _
'you know that you have just 2 items in : CellNo, and play with that.
For i= 0 to 1
Item.CellNo(i) ' do something with ..
End For
Next
also read this : vb.net datatable Serialize to json
Solved the problem by using CellNo as an array
`"CellNo":[
"072685345",
"0728589303"
]
For Each item In listOf
list.ListPerson.Add(item)
Debug.WriteLine(item.Name + " " + item.LastName)
For Each i In item.CellNo
Debug.WriteLine(i)
Next
Next
display
Junius Lekgwara
Cell No: 072685345
Cell No: 0728589303
Phuti Gravel
Cell No: 08377777777
Cell No: 089888888888
Donald Gravel
Cell No: 0791408989
Cell No: 0117689009