Tôi có một thiết bị đầu cuối WCF rằng cũng giống như ví dụ:POST JSON từ điển mà không cần Key/Value chữ
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")]
Stream DoWork(Dictionary<string, string> items);
Để vượt qua bất cứ điều gì để dịch vụ của tôi, tôi phải cấu trúc JSON của tôi như ví dụ:
{"items":[{"Key":"random1","Value":"value1"}, {"Key":"random2","Value":"value2"}]}
Những gì tôi thực sự muốn nó trông như thế này là:
{"items":{"random1":"value1","random2":"value2"}}
có cách nào để thực hiện điều này?
Kiểm tra –
Christie
@NewBeeee - Nó không dẽ. Bạn muốn đặt [DataContractJsonSerializerSettings.UseSimpleDictionaryFormat] (https://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.usesimpledictionaryformat.aspx) nhưng nó không bao giờ bị lộ ra, vì vậy bạn sẽ cần để thay thế toàn bộ bộ nối tiếp. Xem https://stackoverflow.com/questions/6792785 hoặc https://stackoverflow.com/questions/11003016. Có thể https://stackoverflow.com/questions/33554997 cũng sẽ được yêu cầu. – dbc
@NewBeeee - Thực ra tôi nghĩ https://stackoverflow.com/questions/6792785/replace-wcf-default-json-serialization là bản sao. – dbc