Json WCF 服务中的结果格式

Json Result Format in WCF Services

下午好,我有一个 Json 格式的输出,我需要保持与这里的图片完全一样,但它看起来像这样,我可以做什么或让它显示注册数字作为每个结果的顶部?

格式需要

实际格式

我通过Entity Framework6得到结果;我按照 [OperationContract]

中指定的格式制作
    [OperationContract]
    [WebInvoke(Method = "GET", 
     ResponseFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Wrapped, 
     UriTemplate = "getAllProduct/{value}")]
    [return: MessageParameter(Name = "Articulos")]        
    List<Product> GetAllProduct(string value);

感谢您的帮助

您可以使用 Json.Net 并返回一个对象 Dictionary<int,Product>

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