visual-studio Visual Studio 2010 中的 json 支持

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2814894/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:57:00  来源:igfitidea点击:

json support in visual studio 2010

c#visual-studiojsonvisual-studio-2010silverlight-4.0

提问by jnsohnumr

I'm trying to work on a new project parsing some JSON data for a Silverlight 4 project (specifically created as a "Silverlight Business Application - Visual C#" project) using C# in Visual Studio 2010, and I can't find how to include the references to have parsers and native object support for JSON data.

我正在尝试使用 Visual Studio 2010 中的 C# 处理一个新项目,为 Silverlight 4 项目(专门创建为“Silverlight 业务应用程序 - Visual C#”项目)解析一些 JSON 数据,但我找不到如何包含对 JSON 数据具有解析器和本机对象支持的引用。

As far as I know my development tools are up to date (checked MS update).

据我所知,我的开发工具是最新的(检查 MS 更新)。

I know that I can probably just write my own parser but that seems like re-inventing the wheel. Below are some lines that work in VS 2008 in another project of ours (can't post the files due to their being part of a business app):

我知道我可能只能编写自己的解析器,但这似乎是在重新发明轮子。以下是我们另一个项目中 VS 2008 中的一些行(由于它们是商业应用程序的一部分,因此无法发布文件):

using System.Json;

using System.Json;

results = (JsonObject)JsonObject.Load(e.Result);

results = (JsonObject)JsonObject.Load(e.Result);

I hope my description is adequate.

我希望我的描述是充分的。

Thanks for looking,

谢谢你看

jnsohnumr

编号

回答by Bob

I use System.Web.Script.Serialization.JavaScriptSerializer

我使用System.Web.Script.Serialization.JavaScriptSerializer

However, since it does not work in Visual Studio 2010 without configuration, you'll have to figure out how to make it work yourself.

但是,由于它在没有配置的情况下无法在 Visual Studio 2010 中工作,因此您必须自己弄清楚如何使其工作。

回答by mheckmann

I've been using Json.Net. (http://james.newtonking.com/pages/json-net.aspx) to serialize.

我一直在使用 Json.Net。( http://james.newtonking.com/pages/json-net.aspx) 进行序列化。

[Update: http://json.codeplex.com/for latest version]

[更新:http: //json.codeplex.com/最新版本]

[Update Sept 27 2017: https://github.com/JamesNK/Newtonsoft.Jsonlatest version no longer works in visual studio 2010]

[2017 年 9 月 27 日更新:https: //github.com/JamesNK/Newtonsoft.Json最新版本在 Visual Studio 2010 中不再有效]

回答by Dyer

Here you can find a very well-written open-source solution for parsing JSON data:
http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html

在这里你可以找到一个非常好的解析 JSON 数据的开源解决方案:http:
//techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-自己的解析器为 JSON.html

It is not native, but I have used it recently and did the job...

它不是本地的,但我最近使用过它并完成了工作......

回答by Justin

Add a reference to System.Json. Add a reference to System.Json. I just did it and now my using statement is working fine.

添加对 System.Json 的引用。添加对 System.Json 的引用。我刚刚做到了,现在我的 using 语句工作正常。