我最近從RC2遷移到1.0,並且我在web api響應中遇到了問題。從RC2遷移到1.0:從控制器動作返回'動態'會導致奇怪的Web API響應
對於行動
public dynamic GetCountries(string startsWith)
{
return Ok(_countryService.GetList(startsWith));
}
JSON響應在RC2
[{
"CountryCode": "ANG",
"CountryName": "Angola"
},
{
"CountryCode": "ANT",
"CountryName": "Antigua and Barbuda"
}]
JSON響應在1.0
{
"value": [
{
"countryCode": "ANG",
"countryName": "Angola"
},
{
"countryCode": "ANT",
"countryName": "Antigua and Barbuda"
}],
"formatters": [],
"contentTypes": [],
"declaredType": null,
"statusCode": 200
}
對於動態類型,1.0中的響應添加了對象包裝器,而這種情況在屬性較低的情況下並非如此。 有沒有什麼我在遷移時做錯了?
Project.json
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.IdentityModel.Tokens": "5.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": { }
},
https://github.com/aspnet/Announcements/issues/194 –
嗯,謝謝。但那是駱駝案件的問題。在我的數據中附加包裝有什麼問題。 – Ruchan