2010-11-12 227 views
0

byrefrence ParametrizedConstructor对象下面是我的JSON字符串格式化反序列化JSON与Json.NET

{ “aliasname的”: “ysiCountryInfo”, “数据类”:{ “说明”: “美国111”, “守则” : “USA”, “WriteOffTaxPointAdjustment”:0 “IndexationRounding”:6}}

我想反序列化对象到下面类

Explicit选项在 选项严格论

进口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 

末命名空间

凡财产 “数据类” 是从 “Common.DataClasses” 任何类的类型。

并且这里的所有类都有接受ByRef LoginCredential Object的参数化构造函数。

而且我的代码如下:

昏暗loginData作为新ysiLoginData()

With loginData 
    .Server = "xxxxx" 
    .Platform = ServerType.SqlServer 
    .Database = "xxxx"  
    .UserName = "xx" 
    .Password = "xxxxx" 
    .DeveloperMode = True 
    End With 

昏暗SessionKey作为新ysiSessionKey(loginData)

昏暗strJSON的String = HttpUtility.UrlDecode(背景.Request.Form.ToString())

Dim objJSON As JSONFormatClass(Of ysiCountryInfo)= JsonConvert.DeserializeObject(Of JSONFormatClass(Of ysiCoun (strJSON)

json字符串格式:{“AliasName”:“ysiCountryInfo”,“DataClass”:{“Description”:“美国111”,“Code”:“usa”,“WriteOffTaxPointAdjustment”: 0,“IndexationRounding”:6}}

这里“ysiCountryInfo”是我想转换我的“DataClass”属性的类类型。 “ysiCountryInfo”具有参数化的构造函数,它需要参考“ysiSessionKey”的参数。

昏暗objCountryInfo作为新ysiCountryInfo(ysiSessionKey)

我收到错误为JSON的JsonSerializerInternalReader.js文件在行#808

对象createdObject = contract.ParametrizedConstructor.Invoke(constructorParameters.Values.ToArray( ));

因为constructorParameters.Values是空

请帮我尽快解决这个问题。

感谢 Dhiren米斯特里

回答

0

抱歉,我实施了不正确。

我已经通过修改我的通用类DataClass属性如下解决了这个问题。

Private _DataClass As ItemType 
Public Property DataClass() As ItemType 
      Get 
       If _DataClass Is Nothing Then 
        Dim loginData As New ysiLoginData() 
        With loginData 
         .Server = "xxxx" 
         .Platform = ServerType.SqlServer 
         .Database = "xxx" 
         .UserName = "xx" 
         .Password = "xxx" 
         .DeveloperMode = True 
        End With 

        Dim SessionKey As New ysiSessionKey(loginData) 

        Dim args As Object() = {SessionKey} 

        _DataClass = DirectCast(Activator.CreateInstance("YSI.Common", String.Format("{0}", GetType(ItemType).ToString()), True, BindingFlags.Instance Or BindingFlags.Public, Nothing, args, Nothing, Nothing).Unwrap(), ItemType) 

       End If 
       Return _DataClass 
      End Get 
      Set(ByVal value As ItemType) 
       _DataClass = value 
      End Set 
     End Property