JonyTolengo
asked on
I have a problem when deserialize a JSON string in my VB.NET client
Hi,
I have this JSON string, generated by my web services.
{
"status":"OK",
"userId":"CSDEMO",
"name":"Administrador Del Sistema",
"rol":0,
"Areas":[
{
"Id":1,
"Name":"COSTOS_Y_GASTOS"
},
{
"Id":2,
"Name":"VENTAS_BULK"
},
{
"Id":3,
"Name":"VENTAS_CR"
},
{
"Id":4,
"Name":"CARTERA_ANEJAMIENT OS"
},
{
"Id":5,
"Name":"BULK"
},
{
"Id":6,
"Name":"VENTAS_GASES_ENVAS ADOS"
},
{
"Id":7,
"Name":"COSTOS_Y_GASTOS_CR "
},
{
"Id":8,
"Name":"CILINDROS"
},
{
"Id":9,
"Name":"VENTAS_INTEGRADAS_ GENVASADOS "
},
{
"Id":10,
"Name":"COSTOS_Y_GASTOS_JD E_90"
}
]
}
Following the code to deserialize the JSON text.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- '
Dim TextoJason As String = HERE THE JSON STRING
Dim TheMobileUser As New MobileUser
Dim ms As New MemoryStream(System.Text.E ncoding.Un icode.GetB ytes(Texto Jason))
Dim serializer As System.Runtime.Serializati on.Json.Da taContract JsonSerial izer = New System.Runtime.Serializati on.Json.Da taContract JsonSerial izer(TheMo bileUser.G etType())
TheMobileUser = serializer.ReadObject(ms)
ms.Close()
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
This is the class I used in the client side, (exactly as I definied in the server side to serialize the to JSON string).
Public Class MobileUser
Private _status As String
Public Property status() As String
Get
Return _status
End Get
Set(ByVal value As String)
_status = value
End Set
End Property
Private _userId As String
Public Property userId() As String
Get
Return _userId
End Get
Set(ByVal value As String)
_userId = value
End Set
End Property
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 _rol As Integer
Public Property rol() As Integer
Get
Return _rol
End Get
Set(ByVal value As Integer)
_rol = value
End Set
End Property
Private _Areas As List(Of Area)
Public Property Areas As List(Of Area)
Get
Return _Areas
End Get
Set(ByVal value As List(Of Area))
_Areas = value
End Set
End Property
Public Sub New()
Areas = New List(Of Area)
End Sub
End Class
Public Class Area
Private _Id As Integer
Private _Name As String
Public Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = Name
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal Id As Integer, ByVal Name As String)
_Name = Name
_Id = Id
End Sub
End Class
The problem is becouse the NAME of the Areas is not loaded into the class (become NOTHING)
Please, see the attached picture:
Thanks in advance,
Jonny
I have this JSON string, generated by my web services.
{
"status":"OK",
"userId":"CSDEMO",
"name":"Administrador Del Sistema",
"rol":0,
"Areas":[
{
"Id":1,
"Name":"COSTOS_Y_GASTOS"
},
{
"Id":2,
"Name":"VENTAS_BULK"
},
{
"Id":3,
"Name":"VENTAS_CR"
},
{
"Id":4,
"Name":"CARTERA_ANEJAMIENT
},
{
"Id":5,
"Name":"BULK"
},
{
"Id":6,
"Name":"VENTAS_GASES_ENVAS
},
{
"Id":7,
"Name":"COSTOS_Y_GASTOS_CR
},
{
"Id":8,
"Name":"CILINDROS"
},
{
"Id":9,
"Name":"VENTAS_INTEGRADAS_
},
{
"Id":10,
"Name":"COSTOS_Y_GASTOS_JD
}
]
}
Following the code to deserialize the JSON text.
--------------------------
Dim TextoJason As String = HERE THE JSON STRING
Dim TheMobileUser As New MobileUser
Dim ms As New MemoryStream(System.Text.E
Dim serializer As System.Runtime.Serializati
TheMobileUser = serializer.ReadObject(ms)
ms.Close()
--------------------------
This is the class I used in the client side, (exactly as I definied in the server side to serialize the to JSON string).
Public Class MobileUser
Private _status As String
Public Property status() As String
Get
Return _status
End Get
Set(ByVal value As String)
_status = value
End Set
End Property
Private _userId As String
Public Property userId() As String
Get
Return _userId
End Get
Set(ByVal value As String)
_userId = value
End Set
End Property
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 _rol As Integer
Public Property rol() As Integer
Get
Return _rol
End Get
Set(ByVal value As Integer)
_rol = value
End Set
End Property
Private _Areas As List(Of Area)
Public Property Areas As List(Of Area)
Get
Return _Areas
End Get
Set(ByVal value As List(Of Area))
_Areas = value
End Set
End Property
Public Sub New()
Areas = New List(Of Area)
End Sub
End Class
Public Class Area
Private _Id As Integer
Private _Name As String
Public Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = Name
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal Id As Integer, ByVal Name As String)
_Name = Name
_Id = Id
End Sub
End Class
The problem is becouse the NAME of the Areas is not loaded into the class (become NOTHING)
Please, see the attached picture:
Thanks in advance,
Jonny
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thansk so much... its works fine...
No hay de queso, no mas de papa
Open in new window
by :
Open in new window
I apologize