Json.NET
简而言之,这是一个可以用于.NET的Json辅助工具类。它可以将对对象序列化为json字符串。下面是一个我自己写的用在ashx中的例子 using System; using System.Data; namespace WebApplication1 /// $codebehindclassname$ 的摘要说明 /// [WebService(Namespace = " http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class GetData : IHttpHandler { public void ProcessRequest(HttpContext context) NorthwindDataContext db = new NorthwindDataContext(); JsonSerializerSettings settings = new JsonSerializerSettings(); } public bool IsReusable
在页面中使用jquery调用的方式如下 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jqueryGetOrdersbyajax.aspx.cs" Inherits="WebApplication1.jqueryGetOrdersbyajax" %> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml"> <% = minjquery %>
value=" < " /> value=" >> " />
LOADING....
其官方的资料如下,请参考 http://james.newtonking.com/projects/json-net.aspx The Json.NET library makes working with JavaScript and JSON formatted data in .NET simple. Quickly read and write JSON using the JsonReader and JsonWriter or serialize your .NET objects with a single method call using the JsonSerializer. Json.NET CodePlex Project Json.NET Download Features
Example Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008,12,28); product.Price = 3.99M; product.Sizes = new string[] { "Small","Medium","Large" }; string json = JsonConvert.SerializeObject(product); //{ // "Name": "Apple", // "Expiry": new Date(1230422400000), // "Price": 3.99, // "Sizes": [ // "Small", // "Medium", // "Large" // ] //} Product deserializedProduct = JsonConvert.DeserializeObject Documentation Json.NET - Quick Starts & API Documentation History Json.NET grew out of projects I was working on in late 2005 involving JavaScript,AJAX and .NET. At the time there were no libraries for working with JavaScript in .NET so I began to grow my own. Starting out as a couple of static methods for escaping JavaScript strings,Json.NET evolved as features were added. To add support for reading JSON a major refactor was required and Json.NET will split into the three major classes it still uses today,JsonReader,JsonWriter and JsonSerializer. Json.NET was first released in June 2006. Since then Json.NET has been downloaded thousands of times by developers and is used in a number of major projects open source projects such as MonoRail,Castle Project's MVC web framework,and Mono,an open source implementation of the .NET framework.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |