使用 Json.NET 将 JSON 反序列化为 byrefrence ParametrizedConstructor 对象
下面是我的 JSON 格式的字符串
{"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6} On
我想将对象反序列化到下面的类中
Option Explicit 选项严格导入
BaseApp.ysiBaseData 导入 Common.DataClass 导入系统命名
空间数据类
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 对象的参数化构造函数。
我的代码如下:
Dim loginData As New ysiLoginData()
With loginData
.Server = "xxxxx"
.Platform = ServerType.SqlServer
.Database = "xxxx"
.UserName = "xx"
.Password = "xxxxx"
.DeveloperMode = True
End With
Dim SessionKey As New 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”具有参数化构造函数,需要引用“ysiSessionKey”参数。
Dim objCountryInfo as New ysiCountryInfo(ysiSessionKey)
我在 JSON 的 JsonSerializerInternalReader.js 文件第 # 808 行处遇到错误
object createdObject = Contract.ParametrizedConstructor.Invoke(constructorParameters.Values.ToArray());
因为 constructorParameters.Values 为 Null
请帮我尽快解决这个问题。
谢谢 迪伦·米斯特里
Below is my JSON formated String
{"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}}
I would like to deserialize object into below class
Option Explicit On
Option Strict On
Imports BaseApp.ysiBaseData
Imports Common.DataClasses
Imports Systems
Namespace 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
End Namespace
Where Property "DataClass" is type of any class from "Common.DataClasses".
And all class in this has Parametrized constructor which accept ByRef LoginCredential Object.
And My Code is below:
Dim loginData As New ysiLoginData()
With loginData
.Server = "xxxxx"
.Platform = ServerType.SqlServer
.Database = "xxxx"
.UserName = "xx"
.Password = "xxxxx"
.DeveloperMode = True
End With
Dim SessionKey As New 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 string format : {"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}}
here "ysiCountryInfo" is class type into which i would like to convert my "DataClass" property. "ysiCountryInfo" has parametrized constructor which requires parameter of "ysiSessionKey" by ref.
Dim objCountryInfo as New ysiCountryInfo(ysiSessionKey)
I am getting Error into JsonSerializerInternalReader.js file of JSON at line # 808
object createdObject = contract.ParametrizedConstructor.Invoke(constructorParameters.Values.ToArray());
Because constructorParameters.Values is Null
Please help me to solve this problem ASAP.
Thanks
Dhiren Mistry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,我的实施不正确。
我通过修改我的通用类 DataClass 属性解决了这个问题,如下所示。
Sorry i was implemented its incorrectly.
I had solve this problem by modifying my Generic Class DataClass Property As Below.