【发布时间】:2015-07-03 03:33:04
【问题描述】:
所以我查看了很多帖子,但我仍在努力将这个 JSON 对象序列化为类。 JSON结构是这样的
{"value":{"HashTag":"12342345636","companyname":"my test company","LeadDetail":{"id":"1","firstname":"john","lastname":"clark","email":"emak@mai.com","phone":"9874534444"}}}
我的班级结构如下:
<Serializable> _
Public Class LeadDetailCall
Public Property Hash() As String
Get
Return m_Hash
End Get
Set(value As String)
m_Hash = value
End Set
End Property
Private m_Hash As String = ""
Public Property CompanyName() As String
Get
Return _CompanyName
End Get
Set(value As String)
_CompanyName = value
End Set
End Property
Private _CompanyName As String = ""
Public Property Details() As List(Of LeadDetail)
Get
Return _Details
End Get
Set(ByVal value As List(Of LeadDetail))
_Details = value
End Set
End Property
Private _Details As List(Of LeadDetail)
End Class
<Serializable> _
Public Class LeadDetail
Private _id As String = ""
Private _firstname As String = ""
Private _lastname As String = ""
Private _email As String = ""
Private _phone As String = ""
Public Property id() As String
Get
Return _id
End Get
Set(value As String)
_id = value
End Set
End Property
Public Property firstname() As String
Get
Return _firstname
End Get
Set(ByVal value As String)
_firstname = value
End Set
End Property
Public Property lastname() As String
Get
Return _lastname
End Get
Set(ByVal value As String)
_lastname = value
End Set
End Property
Public Property email() As String
Get
Return _email
End Get
Set(ByVal value As String)
_email = value
End Set
End Property
Public Property phone() As String
Get
Return _phone
End Get
Set(ByVal value As String)
_phone = value
End Set
End Property
End Class
我这样称呼:
<WebMethod()> _
Public Function SendLeadDetails(ByVal value As Object) As UpdateResponse
Dim CurCall As LeadDetailCall = JsonConvert.DeserializeObject(Of LeadDetailCall)(value)
End Function
我尝试了什么?使用 JavaScriptSerializer,使用http://jsontodatacontract.azurewebsites.net/ 抓取stackoverflow 为例。这么多的事情,我在这一点上很慌张。所以我不断收到以下无效转换异常错误。
Conversion from type 'Dictionary(Of String,Object)' to type 'String' is not valid.
如果有人可以帮助我,我将非常感激:)
【问题讨论】:
-
您的类暗示您期望或希望允许 JSON 中的集合,但这不是它的构造方式。如果是这样,您可以发布一个包含多个条目(或链接)的示例
标签: asp.net json vb.net web-services serialization