If I may recommend: Use a web service (ASMX) to grab your data. ASP.Net supports automatic serialization to XML or JSON, all you have to do is return an array of objects that have a ToString() function.
For example, I've got a table in SQL Server of primitive types (no custom types). Using LINQ for data access, I query my table in the ASMX file and return an array of the LINQ type. When called from jQuery, the ASMX file converts that array into JSON automatically. On the client side, my script header contains this: function letterClick(data) { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "getData.asmx/myFunction", data: "{'myVariable':'" + data + "'}", dataType: "json", success: function(json) { success(json); }, }); } function success(json) { for (var i = 0; i < json.d.length; i++) { // Do Stuff with returned JSON } } On Thu, Jan 22, 2009 at 11:46 PM, JQueryProgrammer <jain.ashis...@gmail.com>wrote: > > I am trying to use JSON with jquery and .Net. I am using json2.js for > JavaScript and Newtonsoft.JSON for .Net serialization. Here goes my > code: > > JavaScript > ------------------------------------------------------------------- > $.ajax({ > url: "http://localhost/JSONSample/default.aspx", > method: "GET", > datatype: "json", > contentType: "application/json; charset=utf-8", > data: {name: 'User'}, > success: function(result) { > var oResult = JSON.parse(result); > alert(oResult.Guid); > }, > error: function() { > alert("Some error occured"); > } > }); > > Server side code > -------------------------------------------------------------------- > protected void Page_Load(object sender, EventArgs e) > { > if(Request.Params["name"] != null && Request.Params["name"].ToString > () != "") > { > GetName(); > } > } > > public void GetName() > { > System.Web.Script.Serialization ser = new > System.Web.Script.Serialization(); > System.Text.StringBuilder oBuilder = new > System.Text.StringBuilder(); > > oBuilder.Append("{"); > oBuilder.AppendFormat("'{0}' : '{1}'", "Guid", Guid.NewGuid()); > oBuilder.Append("}"); > > string json = ser.Serialize(oBuilder.ToString()); > Response.Write(json); > Response.Flush(); > Response.Close(); > } > > I am able to get the result in success function. But the oResult.Guid > is undefined. When I am trying to alert oResult, it gives me: > > { 'Guid' : '16ba666a-cd2a-41b6-b0b1-5f072d44d488' } > > Can anyone help me why is the oResult.Guid undefined..? >