. net web服务无法处理JSON格式的复杂对象
本文关键字:格式 复杂 对象 JSON 处理 web 服务 net | 更新日期: 2023-09-27 18:09:59
您可以在这里找到我的web服务内容:
[ServiceContract]
public interface IProcessing
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "person/{id}")]
Person GetPerson(string id);
}
我有两个模型,人物和图片。当我尝试以JSON格式从web服务获取图片时,一切都很好,WS返回的结果是正确的。
但这是不一样的,当我试图发送Person对象。
你可以在这里找到我的模型属性:
Person :
{
using System;
using System.Runtime.Serialization;
/// <summary>
/// Class which define the object Person.
/// </summary>
[DataContract]
public class Person
{
#region Constructor
/// <summary>
/// Constructor
/// </summary>
public Person()
{
}
:
/// <summary>
/// Class which define the object Team.
/// </summary>
[DataContract]
public class Picture
{
#region Constructor
/// <summary>
/// Constructor
/// </summary>
public Picture()
{
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the id of the picture
/// </summary>
[DataMember]
public int ID { get; set; }
/// <summary>
/// Gets or sets the url of the picture
/// </summary>
[DataMember]
public string URL { get; set; }
/// <summary>
/// Gets or sets the color code of the picture
/// </summary>
[DataMember]
public string ColorCode { get; set; }
#endregion
}
}
是否在Person header中设置了已知类型属性?这是复杂对象的好例子https://msdn.microsoft.com/en-us/library/ms730167 (v = vs.110) . aspx