这是我的困境.我正在使用RESTful ASP.NET服务,尝试使用以下格式返回JSON字符串的函数:
{"Test1Key":"Test1Value","Test2Key":"Test2Value","Test3Key":"Test3Value"}
Run Code Online (Sandbox Code Playgroud)
但我会以这种格式得到它:
[{"Key":"Test1Key","Value":"Test1Value"},
{"Key":"Test2Key","Value":"Test2Value"},
{"Key":"Test3Key","Value":"Test3Value"}]
Run Code Online (Sandbox Code Playgroud)
我的方法看起来像这样:
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Dictionary<string, string> Test(String Token)
{
if (!IsAuthorized(Token))
return null;
if (!IsSecure(HttpContext.Current))
return null;
Dictionary<string, string> testresults = new Dictionary<string, string>();
testresults.Add("Test1Key", "Test1Value");
testresults.Add("Test2Key", "Test2Value");
testresults.Add("Test3Key", "Test3Value");
return testresults;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法只使用内置的ASP.NET工具摆脱那些"Key"和"Value"标签?(即,如果可以避免的话,我宁愿不使用JSON.NET)
非常感谢!:)