Deserializing some JSON with JSON.NET

陌路散爱 提交于 2019-12-04 13:02:35

I would recomend that you upgrade to .net framework 3.5 and use ASP.Net MVC to build your json services. See:

http://msmvps.com/blogs/omar/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx

I realise this question is about 3 years old, but I thought I'd just add that if you want to build a JSON based Api, NancyFx is awesome: http://nancyfx.org/

EDIT: An example as requested, really easy. To get started just add the nancyfx asp package to a web project via NuGet. (if you're adding it to an existing app on a sub path, you'll need to add a location to the web.config, otherwise you're good to go)

using Nancy;
using Nancy.ModelBinding;

public class Api : NancyModule
        {
            public Api()
            {
                Get["/api/order/create"] = x => 
                { 
                    var order = this.Bind<Order>(); //xml/json negotiated based on content header

                    var result = ... // Do stuff here

                    return Response.AsJson(result); 
                };
            }       
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!