Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务中的Json结果格式_C#_Json_Wcf - Fatal编程技术网

C# WCF服务中的Json结果格式

C# WCF服务中的Json结果格式,c#,json,wcf,C#,Json,Wcf,各位下午好,我有一个Json格式的输出,我需要保持与这里的图片完全相同,但它看起来是这样的,我可以或者我可以让它在每个结果的顶部显示注册号吗 格式需要 实际格式 我通过实体框架6得到结果;我按照[运营合同]中规定的格式制作 [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodySty

各位下午好,我有一个Json格式的输出,我需要保持与这里的图片完全相同,但它看起来是这样的,我可以或者我可以让它在每个结果的顶部显示注册号吗

格式需要

实际格式

我通过实体框架6得到结果;我按照[运营合同]中规定的格式制作

    [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)
    );
}