C# WCF服务中的Json结果格式
各位下午好,我有一个Json格式的输出,我需要保持与这里的图片完全相同,但它看起来是这样的,我可以或者我可以让它在每个结果的顶部显示注册号吗 格式需要 实际格式 我通过实体框架6得到结果;我按照[运营合同]中规定的格式制作C# WCF服务中的Json结果格式,c#,json,wcf,C#,Json,Wcf,各位下午好,我有一个Json格式的输出,我需要保持与这里的图片完全相同,但它看起来是这样的,我可以或者我可以让它在每个结果的顶部显示注册号吗 格式需要 实际格式 我通过实体框架6得到结果;我按照[运营合同]中规定的格式制作 [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodySty
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "getAllProduct/{value}")]
[return: MessageParameter(Name = "Articulos")]
List<Product> GetAllProduct(string value);
[运营合同]
[WebInvoke(Method=“GET”,
ResponseFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Wrapped,
UriTemplate=“getAllProduct/{value}”)]
[返回:MessageParameter(Name=“Articulos”)]
列出GetAllProduct(字符串值);
感谢您的帮助您可以使用并返回一个对象字典
[OperationContract,WebGet(UriTemplate=“getAllProduct/{value}”)]
public System.ServiceModel.Channels.Message GetAllProduct(字符串值)
{
字典dict=。。。。。。。
WebOperationContext.Current.OutgoingResponse.ContentType=“应用程序/json”;
返回WebOperationContext.Current.CreateTextResponse(
JsonConvert.SerializeObject(dict)
);
}
尝试删除属性[return:MessageParameter(Name=“Articulos”)]。这应该可以满足您的需要如果删除该属性,请显示消息“GetAllProductResult”@ockert非常感谢,我有所需的格式,非常好的解决方案
[OperationContract, WebGet(UriTemplate = "getAllProduct/{value}")]
public System.ServiceModel.Channels.Message GetAllProduct(string value)
{
Dictionary<int, Product> dict = .......
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
return WebOperationContext.Current.CreateTextResponse(
JsonConvert.SerializeObject(dict)
);
}