JSON.NET JsonConvert 与 .NET JavaScriptSerializer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11263166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON.NET JsonConvert vs .NET JavaScriptSerializer
提问by Gabbar
What is better to use when it comes to encoding and decoding of JSON in .NET? I have tried both and upto this point JsonConvert seems to be doing a good job. I have used JavaScriptSerializer in the past successfully but have had some problems in the recent past with it. Is it better to use JSON.NET than the .NET class?
在 .NET 中编码和解码 JSON 时使用什么更好?我已经尝试了这两种方法,到目前为止 JsonConvert 似乎做得很好。我过去曾成功地使用过 JavaScriptSerializer,但最近在使用它时遇到了一些问题。使用 JSON.NET 比使用 .NET 类更好吗?
What are the preferred functions for encoding/decoding json using the appropriate library? I use SerializeObject/DeSerializeObject from JSON.NET and Serialize/DeSerialize from .NET.
使用适当的库编码/解码 json 的首选函数是什么?我使用来自 JSON.NET 的 SerializeObject/DeSerializeObject 和来自 .NET 的 Serialize/DeSerialize。
Thanks
谢谢
回答by Haohmaru
I think thisis exactly the kind of comparison you are looking for.
我认为这正是您正在寻找的那种比较。
It basically says that JSON.Net is better because it among other things...
它基本上说 JSON.Net 更好,因为它除其他外......
- Is faster
- Has LINQto JSON support
- Can convertJSON to and from XML
- 是更快
- 有LINQto JSON 支持
- 可以将JSON 与XML 相互转换
In my opinion the only positive, (and it is a small positive), I can see for the built-in serializer is that there is no extra external dependency to manage.
在我看来,唯一的积极因素(这是一个小小的积极因素),我可以看到内置序列化程序没有额外的外部依赖来管理。
Edit: Codeplex is shutting down one day so you can find the comparison hereas well, just search for "Feature comparison" on the page.
编辑:Codeplex 有一天会关闭,因此您也可以在此处找到比较,只需在页面上搜索“功能比较”即可。
回答by frenchie
For a very long time, my app used JavascriptSerializerand saw no real reason to migrate. Even if performance comparisons claim huge percentage gains, we're talking milliseconds.
很长一段时间以来,我的应用程序都在使用JavascriptSerializer,但没有看到迁移的真正理由。即使性能比较声称获得了巨大的百分比收益,我们也在谈论毫秒。
But here's one very very good reason to migrate: JavascriptSerializerisn't available in .Net Corebecause it's part of System.WebSo if you're using JavascriptSerializer, you're stuck and have to migrate to JSON.net
但是这里有一个非常好的迁移理由:JavascriptSerializer不可用,.Net Core因为它是 的一部分System.Web所以如果你正在使用JavascriptSerializer,你就会被卡住,必须迁移到 JSON.net

