PostAsJsonAsync 无法序列化字典中的对象
PostAsJsonAsync cannot serialize an object in Dictionary
我有一些代码负责 post 一些数据到网络 api。我正在尝试 post 字典。但是当请求被 posted.
时,密钥 属性 无法序列化
这是我的代码:
response = await base.HttpClientInstance.PostAsJsonAsync<Dictionary<ItemDto, string>>(url, dummyItems);
有 fiddler 会话摘要:
Content-Type: application/json; charset=utf-8
Host: debug.foo.foo.com
Content-Length: 78
Expect: 100-continue
Connection: Keep-Alive
{"Foo.Contract.Items.ItemDto":"87a0a711-6ecb-4ef5-9aed-04f7573344e1"}
问题出在哪里,有什么想法吗?
乍一看,您似乎需要在 ItemDto
实现中覆盖 ToString
...系统的默认实现只是打印 class 的名称, 例如 Foo.Contract.Items.ItemDto
.
我有一些代码负责 post 一些数据到网络 api。我正在尝试 post 字典。但是当请求被 posted.
时,密钥 属性 无法序列化这是我的代码:
response = await base.HttpClientInstance.PostAsJsonAsync<Dictionary<ItemDto, string>>(url, dummyItems);
有 fiddler 会话摘要:
Content-Type: application/json; charset=utf-8
Host: debug.foo.foo.com
Content-Length: 78
Expect: 100-continue
Connection: Keep-Alive
{"Foo.Contract.Items.ItemDto":"87a0a711-6ecb-4ef5-9aed-04f7573344e1"}
问题出在哪里,有什么想法吗?
乍一看,您似乎需要在 ItemDto
实现中覆盖 ToString
...系统的默认实现只是打印 class 的名称, 例如 Foo.Contract.Items.ItemDto
.