ASMX 始终在 xml 标记内返回 JSON

发布于 2024-10-08 23:04:16 字数 946 浏览 0 评论 0原文

我有返回 json 字符串的 asmx 服务。我使用 DataContractJsonSerializer 类,生成的 json 很好。

当我调用这些服务在 Web 应用程序中使用时,响应始终会重新封装在 xml 标记中。任何摆脱 xml 并仅返回 json 的方法。

响应示例:

< ?xml version="1.0" encoding="utf-8" ?>
< string xmlns="http://whatever.net/">

{"Success":true,"Data":{"RoomList":[{"CreatedAt":"\/Date(1291192978793-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"Reterras numagona alantis","RoomID":44,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":12},{"CreatedAt":"\/Date(1291115544347-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"12122","RoomID":43,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":2},{"CreatedAt":"\/Date(1291115537413-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"12122","RoomID":42,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":2}],"TotalCount":42}}

< / string>

I have asmx services that return json strings. I use DataContractJsonSerializer class and the resulting json is fine.

When I call these services to consume in a web app, the response is always coming backencapsulated in an xml tag. Any ways to get rid of the xml and return only the json.

Example response :

< ?xml version="1.0" encoding="utf-8" ?>
< string xmlns="http://whatever.net/">

{"Success":true,"Data":{"RoomList":[{"CreatedAt":"\/Date(1291192978793-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"Reterras numagona alantis","RoomID":44,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":12},{"CreatedAt":"\/Date(1291115544347-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"12122","RoomID":43,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":2},{"CreatedAt":"\/Date(1291115537413-0800)\/","GameTimeOut":0,"MatchPointingType":0,"MoveTimeOut":0,"Name":"12122","RoomID":42,"SFID":null,"StartingMatchPoints":0,"UpdateAt":null,"UserID":2}],"TotalCount":42}}

< / string>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤单情人 2024-10-15 23:04:16

听起来类似于这个问题:

如何让 ASMX 文件输出 JSON

Sounds similar to this question:

How to let an ASMX file output JSON

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文