开发者

Hashtable as JSON from Web Service

开发者 https://www.devze.com 2023-03-07 07:58 出处:网络
I\'m trying to return a list of key/value pairs as JSON from a web service but getting a serialization error with Hashtable.

I'm trying to return a list of key/value pairs as JSON from a web service but getting a serialization error with Hashtable.

I've used this in other projects and it was working with returning a Hashtable yesterday, however, it would seem something has changed which causes an error to be thrown:

The type System.Col开发者_如何学Clections.Hashtable is not supported because it implements IDictionary.

I've worked around this by using List>, but I don't see why this was previously working and now is not.

My method signature is:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public List<KeyValuePair<string, object>> FindPosts(string type, string searchText, int offset) {


Internal Json serializer is perfectly capable of serializing/deserializing hashtable where Xml serializer is not so you're probably using Xml serializer somewhere in your code without noticing it. Look through your code to make sure that all serializations use Json.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号