下面是我的 JSON 格式字符串
{"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}}
我想将对象反序列化为下面的类
Option Explicit On Option Strict On
导入 BaseApp.ysiBaseData 导入 Common.DataClasses 导入系统
命名空间数据类
Public Class JSONFormatClass(Of ItemType)
Private _Alias As String
Public Property AliasName() As String
Get
Return _Alias
End Get
Set(ByVal value As String)
_Alias = value
End Set
End Property
Private _DataClass As ItemType
Public Property DataClass() As ItemType
Get
Return _DataClass
End Get
Set(ByVal value As ItemType)
_DataClass = value
End Set
End Property
End Class
结束命名空间
其中属性“DataClass”是“Common.DataClasses”中任何类的类型。
并且其中的所有类都有接受 ByRef LoginCredential 对象的参数化构造函数。
我的代码如下:
将 loginData 调暗为新的 ysiLoginData()
With loginData
.Server = "xxxxx"
.Platform = ServerType.SqlServer
.Database = "xxxx"
.UserName = "xx"
.Password = "xxxxx"
.DeveloperMode = True
End With
将 SessionKey 调暗为新的 ysiSessionKey(loginData)
Dim strJSON As String = HttpUtility.UrlDecode(context.Request.Form.ToString())
Dim objJSON As JSONFormatClass(Of ysiCountryInfo) = JsonConvert.DeserializeObject(Of JSONFormatClass(Of ysiCountryInfo))(strJSON)
json 字符串格式:{"AliasName":"ysiCountryInfo","DataClass":{"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}}
这里“ysiCountryInfo”是我想将我的“DataClass”属性转换成的类类型。“ysiCountryInfo”具有参数化的构造函数,它需要 ref 的“ysiSessionKey”参数。
将 objCountryInfo 调暗为新的 ysiCountryInfo(ysiSessionKey)
我在第 808 行的 JSON 的 JsonSerializerInternalReader.js 文件中出现错误
对象 createdObject = contract.ParametrizedConstructor.Invoke(constructorParameters.Values.ToArray());
因为 constructorParameters.Values 是 Null
请帮我尽快解决这个问题。
感谢 Dhiren Mistry