我有一个托管在Microsoft Azure云中的应用程序。此应用程序是一项应用程序服务 我目前有一些JSON序列化的问题。收到的JSON格式不正确。 我的应用程序是一个ASP.NET MVC6。 基本上,我有一个前台,他从控制器(服务器端)接收JSON值。JsonProperty似乎不适用于Windows Azure应用服务
C#服务器侧方法:
[HttpGet]
[Route("domain/search")]
public IActionResult Search(string sn)
{
// DOING MY STUFF
ICollection<MyModel> myobject
return new ObjectResult(myobject);
}
模型类:
public class MyModel
{
[JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Ignore)]
public string Id { get; set; }
[JsonProperty(PropertyName = "sn", NullValueHandling = NullValueHandling.Ignore)]
public string SerialNumber { get; set; }
[JsonProperty(PropertyName = "state", NullValueHandling = NullValueHandling.Ignore)]
public AStateTypeModel? State { get; set; }
[JsonProperty(PropertyName = "description", NullValueHandling = NullValueHandling.Ignore)]
public string Description { get; set; }
.
.
ETC
.
.
}
正确JSON来接收:
[
{
"id":"806c76b5-guid-guid-guid-guid",
"sn":"X00000000000",
"state":"AState",
.
.
ETC
.
.
}
]
当我以本地模式启动应用程序时,一切都很好。我有正确的JSON值和属性名称。 但是在Azure上,前收到了不正确的JSON:
[
{
"Id":"806c76b5-guid-guid-guid-guid",
"SerialNumber":"X00000000000",
"Description":null,
"State":1,
.
.
ETC
.
.
}
]
我认为这是我的地方以及那些目前在Azure服务器之间的包版本的差异,但一切都看起来不错。 JsonProperty
属性似乎被忽略。 我目前使用Windows Azure SDK 2.8,Newtonsoft 9.0.1。和ASPNET.MVC 6.0.0:
依赖关系:
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
"Microsoft.AspNet.Owin": "1.0.0-rc1-final",
"Microsoft.AspNet.SignalR.Redis": "2.2.0",
"Microsoft.AspNet.WebSockets.Server": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-rc1-final",
"Newtonsoft.Json": "9.0.1"
}
我不知道如果我有一些麻烦与JsonFormatter
或类似的东西...... 怎么了? 非常感谢您的帮助!
这些问题不仅在枚举上,而且在所有JSON属性名称上。 我想有 [ { “ID”: “806c76b5-GUID-GUID-GUID-GUID”, “SN”: “X00000000000” } ] 代替 [ { “Id”:“806c76b5-guid-guid-guid-guid”, “SerialNumber”:“X00000000000” } ] –
现在我明白了。我更新了答案...也许天青并没有使用Json.NET,所以你尝试重载默认的Json响应方法, – Nico
我试过了,但没有奏效。我仍然有一个糟糕的JSON .... –