[英]Serialization issue using JsonConvert.SerializeObject (properties missing on server)
I am getting pretty weird behaviour using JsonConvert.SerializeObject. 使用JsonConvert.SerializeObject,我的行为越来越奇怪。
I have a method looking like the following: 我有一个方法如下所示:
public class ServiceController : ApiController
{
public object GetJSONConnectedResponse(object input)
{
return JsonConvert.SerializeObject(input, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});
}
public object GetMediaGallery(int? id)
{
try
{
return GetJSONConnectedResponse(GalleryBLL.GetMediaGallery(id));
}
catch (Exception exc)
{
LogBLL.LogException(exc, HttpContext.Current.Request.RawUrl);
return null;
}
}
}
As you can see, I am using MVC Web API as a service application from which I query ajax-type of data using javascript on the client side. 如您所见,我将MVC Web API用作服务应用程序,通过客户端的javascript从中查询ajax类型的数据。
The method GetMediaGallery returns a holder class of the following structure: 方法GetMediaGallery返回具有以下结构的holder类:
public class MediaGalleryHolder
{
public List<DB_Image> Images { get; set; }
public List<string> SpinFrames { get; set; }
public string FlyoverVideo { get; set; }
}
DB_Images is a complex entity which I populate in a business logic method by calling a stored procedure. DB_Images是一个复杂的实体,我通过调用存储过程以业务逻辑方法填充该实体。 On this complex entity, I have added 2 extra properties.
在这个复杂的实体上,我添加了2个额外的属性。
public partial class DB_Image
{
public string FullPath { get; set; }
public string ThumbPath { get; set; }
}
For some reason, on my local machine, the result serializes correctly (adding both the 2 extra properties), but on the server those extra properties are not added to the result (I know they are populated, but never serialized). 出于某种原因,在我的本地计算机上,结果正确地序列化了(同时添加了2个额外的属性),但是在服务器上,那些额外的属性并未添加到结果中(我知道它们已被填充,但是从未序列化)。
Is this some sort of JSON.NET or MVC Web API versioning issue, how can I go about to troubleshoot or resolve this? 这是某种JSON.NET或MVC Web API版本控制问题,如何解决或解决此问题?
Any help would be greatly appreciated! 任何帮助将不胜感激!
Best, 最好,
tribe84 部落84
Have you tried with annotations on each class? 您是否在每个课程上都尝试了注释? you can try adding [Serializable]
您可以尝试添加[可序列化]
[Serializable]
public partial class DB_Image
{
public string FullPath { get; set; }
public string ThumbPath { get; set; }
}
[Serializable]
public class MediaGalleryHolder
{
public List<DB_Image> Images { get; set; }
public List<string> SpinFrames { get; set; }
public string FlyoverVideo { get; set; }
}
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.