I'm trying to support a legacy app I made a year ago and need to use jQuery AJAX calls to get data from the server. I have a JsonHelper class that I use to serialize DataTable
s and DataSet
s. This normally works fine in .NET 4.0, but .NET 2.0 there is no System.Web.Script.Serialization
library and therefore no JavaScriptSerializer
class.
我正在尝试支持一年前制作的遗留应用程序,需要使用jQuery AJAX调用从服务器获取数据。我有一个JsonHelper类,用于序列化DataTables和DataSet。这通常在.NET 4.0中工作正常,但.NET 2.0没有System.Web.Script.Serialization库,因此没有JavaScriptSerializer类。
I've tried to find another JSON serializer, but so far I can't get anything to work.
我试图找到另一个JSON序列化程序,但到目前为止我无法得到任何工作。
I tried using JSON.NET 2.0 http://json.codeplex.com/releases/view/13099 but it said it needed a higher framework. So I tried JSON.NET 1.3.1 http://json.codeplex.com/releases/view/6987 I could only figure out how to write JSON to a .txt file, and I'd like to just be able to pass the string back to the client.
我尝试使用JSON.NET 2.0 http://json.codeplex.com/releases/view/13099,但它说它需要一个更高的框架。所以我尝试了JSON.NET 1.3.1 http://json.codeplex.com/releases/view/6987我只能弄清楚如何将JSON写入.txt文件,我希望能够通过字符串返回客户端。
I also just tried JsonFx.NET http://jsonfx.net/download/ serialization library (for 2.0). Still couldn't get anything to work.
我也尝试过JsonFx.NET http://jsonfx.net/download/序列化库(适用于2.0)。仍然无法得到任何工作。
I don't know if I'm missing some crucial element of these libraries or if there is an easy solution.
我不知道我是否遗漏了这些库中的一些关键元素,或者是否有一个简单的解决方案。
Thanks in advance
提前致谢
3 个解决方案
#1
5
I used this question's first answer to solve my problem: DataTable to JSON
我用这个问题的第一个答案来解决我的问题:DataTable到JSON
I downloaded the AJAX Extensions 1.0 Library and included "System.Web.Extensions.dll" with my project. http://www.microsoft.com/download/en/details.aspx?id=883
我下载了AJAX Extensions 1.0 Library并在我的项目中包含了“System.Web.Extensions.dll”。 http://www.microsoft.com/download/en/details.aspx?id=883
JavaScriptSerializer
now works.
JavaScriptSerializer现在可以使用了。
#2
1
The Jayrock Library works with all versions of .Net all the way down to 1.x. You'll have to build it yourself for 2.0, but that's no big deal.
Jayrock库可以与.Net的所有版本一起使用,直到1.x.你必须自己为2.0构建它,但这没什么大不了的。
I've used it for the past few months. Nice and simple Json serialization and deserialization.
过去几个月我一直用它。简单的Json序列化和反序列化。
#3
0
Easy (but not elegant) solution is to create a shim in .NET 4 that will call your legacy application via HTTP POST or SOAP and convert result in JSON format with NewtonSoft.Json which works OK on .NET 4.
简单(但不是优雅)的解决方案是在.NET 4中创建一个垫片,它将通过HTTP POST或SOAP调用您的遗留应用程序,并使用NewtonSoft.Json将结果转换为JSON格式,这在.NET 4上运行正常。
#1
5
I used this question's first answer to solve my problem: DataTable to JSON
我用这个问题的第一个答案来解决我的问题:DataTable到JSON
I downloaded the AJAX Extensions 1.0 Library and included "System.Web.Extensions.dll" with my project. http://www.microsoft.com/download/en/details.aspx?id=883
我下载了AJAX Extensions 1.0 Library并在我的项目中包含了“System.Web.Extensions.dll”。 http://www.microsoft.com/download/en/details.aspx?id=883
JavaScriptSerializer
now works.
JavaScriptSerializer现在可以使用了。
#2
1
The Jayrock Library works with all versions of .Net all the way down to 1.x. You'll have to build it yourself for 2.0, but that's no big deal.
Jayrock库可以与.Net的所有版本一起使用,直到1.x.你必须自己为2.0构建它,但这没什么大不了的。
I've used it for the past few months. Nice and simple Json serialization and deserialization.
过去几个月我一直用它。简单的Json序列化和反序列化。
#3
0
Easy (but not elegant) solution is to create a shim in .NET 4 that will call your legacy application via HTTP POST or SOAP and convert result in JSON format with NewtonSoft.Json which works OK on .NET 4.
简单(但不是优雅)的解决方案是在.NET 4中创建一个垫片,它将通过HTTP POST或SOAP调用您的遗留应用程序,并使用NewtonSoft.Json将结果转换为JSON格式,这在.NET 4上运行正常。