0

我有:

Public Class Ticket
  Private _ITicketStyle as ITicketStyle
  Public Property TicketStyle() as ITicketStyle
    Get
      Return _ITicketStyle
    End Get
    Set(value as ITicketStyle)
      _ITicketStyle = value
    End Set
  End Property
End Class

Public Class FlightTicket
    Implements ITicketStyle
    Public Property city() as String
End Class

Public Class MovieTicket
    Implements ITicketStyle
    Public Property name() as String
End Class

和:

Dim ft as New Ticket()
ft.Ticket = New FlightTicket With { .city="NY" }
Dim output1 as String = JsonConvert.SerializeObject(ft) 

我得到:output1 = {"TicketStyle":{"city" : "NY"}}

与:

Dim mt as New Ticket()
mt.Ticket = New MovieTicket With { .name="Transformers" }
Dim output2 as String = JsonConvert.SerializeObject(mt)

我得到:output2 = {"TicketStyle":{"name" : "Transformers"}}

但是我需要:

output1 = {"FlightTicket":{"city": "NY"}} and 
output2={"MovieTicket": {"name": "Transformers"}}

有没有办法实现这一目标?我可以申请JsonProperty("FlightTicket")属性TicketStyle,但需要将MovieTicket对象分配给TicketStyle属性时将其更改为“MovieTicket”。

4

0 回答 0