Configuring WCF data contract for proper JSON response

前端 未结 2 1239
囚心锁ツ
囚心锁ツ 2021-01-24 23:26

I manage a number of Bed & Breakfast websites and run a kind of booking engine to help the client do bookings directly on their website (as opposed to going to another site

相关标签:
2条回答
  • 2021-01-25 00:14

    Ok I found a solution. It required two steps:

    1. Use ExpandoObject to add properties to room_types Object dynamically
    2. Serialize the return object with Newtonsoft.Json and force the service to return plain text
    0 讨论(0)
  • 2021-01-25 00:22

    In your sample of the "proper" json, room_types is not a collection property. In json format, collections are enclosed with [ ], as you have it in your second "wrong" sample. That means that your room_types is in fact an object having two properties "Orchid Room" and "Presidential Suite". Note that the property name with the space is achievable by setting the Name property of the DataMember Attribute: <DataMember(Name:="Orchid Room")>

    0 讨论(0)
提交回复
热议问题