简体   繁体   English

如何在服务器端的WCf服务中从JSON数据解析和识别标头

[英]how to parse and identify header from JSON Data in WCf Service at server side

I've done a project in ASP.NET with C#. 我已经用C#在ASP.NET中完成了一个项目。 Now I need to write a WCF service for this. 现在,我需要为此编写WCF服务。 On the server-side, how can I parse JSON data, and how can I identify the header, body, footer, etc.? 在服务器端,如何解析JSON数据,以及如何识别页眉,正文,页脚等?

You would normally define a data contract which maps to your JSON structure. 通常,您将定义一个映射到JSON结构的数据协定。 You'd then write a service contract which would accept the data contract type in your operation, and WCF does the parsing of the JSON data into the type. 然后,您将编写一个服务协定,该协定将在您的操作中接受数据协定类型,然后WCF会将JSON数据解析为该类型。

I've written a small tool that helps you do that, you can find a link to it in the blog post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas-for-json.aspx . 我编写了一个小工具来帮助您完成此任务,您可以在http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas上的博客文章中找到指向该工具的链接。 -for-json.aspx

An easy way to parse and/or generate JSON data is JSON.NET. 解析和/或生成JSON数据的一种简单方法是JSON.NET。 It's a great library and much better than the built-in JSON serializer. 这是一个很棒的库,比内置的JSON序列化器要好得多。

You can find it at http://json.codeplex.com/ . 您可以在http://json.codeplex.com/上找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM