如何在WCF中返回有效的JSON数组

时间:2013-05-15 06:58:10

标签: c# json wcf rest webinvoke

这是我的webInvoke

[WebInvoke(
        Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "{invoice}/{transtype}/"

        )
    ]

我有这个返回代码

Dictionary<string, object> dic = new Dictionary<string, object>();
        dic.Add("ApprovalStatus", response.ApprovalStatus);
        dic.Add("AuthorizationCode", response.AuthorizationCode);
        dic.Add("CardBalance", response.CardBalance);
        dic.Add("ErrorMessage", response.ErrorMessage);
        dic.Add("InvoiceNumber", response.InvoiceNumber);

        return dic;

我的问题是它没有返回有效的JSON数组

示例结果

 [{"Key":"ApprovalStatus","Value":"CAPTURED"},{"Key":"AuthorizationCode","Value":"TAS926"},{"Key":"CardBalance","Value":null},{"Key":"ErrorMessage","Value":""},{"Key":"InvoiceNumber","Value":"1"},{"Key":"ReferenceNumber","Value":"313506502708"},{"Key":"UniqueCode","Value":"2704"}]

如何将其设为JSON数组?

0 个答案:

没有答案