【发布时间】:2019-12-03 09:41:33
【问题描述】:
我有一个 get 操作,我想从中返回一个字符串。一个例子是
“000875”
当我从完全 .NET 的 Web API 控制器中的控制器返回此字符串时,它的格式如下:
{
"Property": "000875"
}
当我在转换后的 .NET Core 控制器中返回字符串时,它会返回:
{
"$id": "1",
"$type": "System.Net.Http.HttpResponseMessage, System.Net.Http",
"Version": "1.1",
"Content": {
"$id": "2",
"$type": "System.Net.Http.StringContent, System.Net.Http",
"Headers": [
{
"Key": "Content-Type",
"Value": [
"application/json; charset=utf-8"
]
}
]
},
"StatusCode": "OK",
"ReasonPhrase": "OK",
"Headers": [],
"TrailingHeaders": [],
"RequestMessage": null,
"IsSuccessStatusCode": true
}
有趣的是,该值甚至不在其中!
我正在运行一些有趣的 JSON 序列化来使 BreezeJs 与 .NET Core 一起工作。这可能是造成这种怪异的原因:
.AddNewtonsoftJson(opt =>
{
// Let Breeze say how we serialize. This adds in the Type and Id options the way breeze expects
var jsonSerializerSettings = JsonSerializationFns.UpdateWithDefaults(opt.SerializerSettings);
......
我希望有一种方法可以在没有所有这些混乱的情况下让字符串通过。可以吗?
【问题讨论】:
-
你能告诉我们包含返回行的API方法代码吗?
标签: asp.net-core breeze