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」に変更する必要があります。MovieTicketTicketStyle

4

0 に答える 0