解析JSON字符串JSON对象在C#.NET [英] Parse JSON String to JSON Object in C#.NET

查看:215
本文介绍了解析JSON字符串JSON对象在C#.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON字符串返回在.NET我SOAP的Web服务。它如下所示:

I have a JSON String returned by my SOAP web service in .NET. It is as follows:

{checkrecord:[{rollno:ABC2,百分比:参加40:错过了12:34}],表1:[]}

{"checkrecord":[{"rollno":"abc2","percentage":40,"attended":12,"missed":34}],"Table1":[]}

现在我想分析该字符串的JSON对象。我也看了,他们已经用这种线code:

Now I want to parse this string to a JSON Object. I also read this where they have used this line of code:

JObject jsonObj = JObject.Parse(JSON);

JObject jsonObj = JObject.Parse(json);

所以我可以做同样的用我的字符串名称替换JSON。另外,我需要引用任何其他的dll除了NewtonSoft.dll?

So can I do the same by replacing "json" with my string name. Also do I need to reference any other dll except the NewtonSoft.dll ?

顺便说一句,下面是完整的web服务 code

BTW, Here is the full webservice code

推荐答案

使用新JavaScriptSerializer.Deserialize<对象>(jsonString)

您需要System.Web.Extensions程序的DLL相同,导入下列命名空间。

You need System.Web.Extensions dll for the same and import the following namespace.

命名空间:System.Web.Script.Serialization

Namespace: System.Web.Script.Serialization

有关更多信息 <一个href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">MSDN

for more info MSDN

这篇关于解析JSON字符串JSON对象在C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆