在 WCF 中,如何将数据表转换为将以 JSON 存储格式输出而无需类的格式

发布于 2024-10-05 04:38:43 字数 201 浏览 0 评论 0原文

所以这是问题 - 我有一个 DataTable 我希望 WCF (.NET 3.5) 以 ExtJS 等中常用的 JSON 存储格式发送 - 基本上是“Rows[{”Field1”:value,”Field2”:value}, {...}]”,但我找不到正确的结构来反馈给操作合约以将其以这种格式发送出去。

所以需要任何想法或任何进一步的信息。

提前致谢!

So here's the problem - I have a DataTable I want WCF (.NET 3.5) to send out in a JSON store format commonly used in ExtJS, etc - basically "Rows[{"Field1":value,"Field2":value},{...}]" but I cannot find the right structure to feed back to the Operation contract to send it out in this format.

So any ideas, or any further info needed.

Thanks, in advance!

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

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

发布评论

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

评论(1

还给你自由 2024-10-12 04:38:43

AndyPC,不幸的是,你运气不好。

如果您正在处理类型为 IXmlSerialized 的对象,则 WCF JSON 序列化程序首先委托给 IXmlSerialized 方法,从中获取序列化的 XML,将 XML 包装在 JSON 字符串中,然后将其传递。这是 .NET 3.5 中 WCF JSON 模型的主要弱点之一。我认为实体框架(WCF 数据服务)技术尝试更优雅地处理这个问题,但不确定。我建议手动使用 JSON 序列化器并制作一个字符串或手动序列化机制来完成您想要的操作......

AndyPC, unfortunately, you're out of luck.

If you're dealing with an object whose type is an IXmlSerializable, the WCF JSON serializer delegates to IXmlSerializable methods first, gets the serialized XML out of them, wraps the XML in a JSON string, and just passes that on. This is one of the major weaknesses of the WCF JSON model in .NET 3.5. I think the entity framework (WCF Data Services) technologies try to handle this more elegantly, but not sure. I'd recommend manually using the JSON serializer and crafting up a string or a manual serialization mechanism that does what you want...

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